c#与最牛vb算法比拼 by Error
文章来源: http://www.zoesan.com By Error 302777528转载请注明出处
以上vb用到指针技术查找字符串与c#一般的.indexof()查找相比较,明显看出谁快谁慢。
VB:
Option Explicit
'指针方法操作字符串
'Copy一个字符串到缓存中
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function lstrcpy Lib "Kernel32.dll" Alias "lstrcpyW" (lpszString1 As Any, lpszString2 As Any) As Long
'通过指针获取字符串的长度
Public Declare Function lstrlen Lib "Kernel32.dll" Alias "lstrlenW" (ByVal lpszString As Long) As Long
Public Function FindTextInStr(ByVal OriStr As String, ByVal strText As String) As Long
Dim Buff() As Byte '声明一个Byte数组
Dim Pointer As Long '声明一个变量,用于存储指针
Pointer = StrPtr("Love")
ReDim Buff(0 To lstrlen(Pointer) * 2 - 1) As Byte '分配缓存大小,由于得到的是Unicode,所以乘以2
lstrcpy Buff(0), ByVal Pointer '复制到缓存Buff中
' Me.Caption = InStr(1, Buff, StrConv("o", vbfromUnicode))
FindTextInStr = InStr(OriStr, StrConv(strText, vbfromUnicode)) '查找子字符串位置
' Debug.Print Buff '显示到text1中
End Function
Private Sub Command1_Click()
Dim sTime As Long
sTime = GetTickCount
For i = 1 To 10000
Call comPareTime
Next
sTime = GetTickCount - sTime
Label1.Caption = "查找10000次粤ICP备05004654号花费" & sTime & "ms"
End Sub
Sub comPareTime()
Dim i1 As Long
i1 = FindTextInStr(RichTextBox1.Text, "粤")
End Sub
'''''''''''''''''''''''''''''''''''''''''''
C#代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebContro
相关文档:
这里是 利用replace 函数 在vb中实现 消除空行的一个程序
这里的容器是richtext
可以扩充到其他容器 和其他字符 用于编写查找替换功能
'--------------------------------------------------------------------------------------------
' 消除空行 , 利用instr函数, 搜索文本里的vbcrlf(回车 + 换行), 两个回车替换 ......
1、DateTime 数字型
System.DateTime currentTime=new System.DateTime();
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now;
1.2 取当前年
&nb ......
1、先把VB编译好的DLL文件放到系统的SYSTEM32文件夹下
2、用regsvr32注册这个DLL文件
3、Pb下调用
oleobject ole_1
ole_1=create oleobject
long ll_ret
ll_ret=ole_1.connecttonewobject( 'add.addstring ')//其中add为VB的工程名,addstring为VB的类模块名
string ls_message, ......
我们今天来讲一下该体系结构中的XmlTextReader类,该类提供对Xml文件进行读取的功能,它可以验证文档是否格式良好,如果不是格式良好的Xml文档,该类在读取过程中将会抛出XmlException异常,可使用该类提供的一些方法对文档节点进行读取,筛选等操作以及得到节点的名称和值,请牢记:XmlTextReader是基于流模型的实现,打个 ......
常用的系列化定义(using System.Xml.Serialization;)
[XmlAttribute("name")] // 定义<Tag name="…"></Tag>
[XmlElement("label")] // 定义<label>…</label>
[XmlIgnoreAttrib ......