''VB:
Option Explicit
''指针方法操作字符串
''Copy一个字符串到缓存中
''site:www.zoesan.com
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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Powered BY Error