怎樣取得一個字符串在另外一個字符串中出現的次數?
PublicFunctionsCount(String1AsString,String2AsString)AsInteger
DimIAsInteger,iCountAsInteger
I=1
Do
If(I>Len(String1))ThenExitDo
I=InStr(I,String1,String2,vbTextCompare)
IfIThen
iCount=iCount 1
I=I 2
DoEvents
EndIf
LoopWhileI
sCount=iCount
EndFunction
□怎樣在一個字符串中完全刪除裡面的另外一個字符串?
FunctionStringCleaner(sAsString,_
SearchAsString)AsString
DimiAsInteger,resAsString
res=s
DoWhileInStr(res,Search)
i=InStr(res,Search)
res=Left(res,i-1)&_
Mid(res,i 1)
Loop
StringCleaner=res
EndFunction
□怎樣在一個字符串中刪除裡面的另外一個字符串?
PublicSubsRemove(String1AsString,String2AsString)
DimIAsInteger
I=1
Do
If(I>Len(String1))ThenExitDo
I=InStr(1,String1,String2)
IfIThen
String1=Left$(String1,I-1) Mid$(String1,I Len(String2) 1)
I=I 2
DoEvents
EndIf
LoopWhileI
EndSub
□怎樣在一個字符串中替換裡面的另外一個字符串?
PublicSubsReplace(String1AsString,String2AsString,RepStringAsString)
DimIAsInteger
I=1
Do
If(I>Len(String1))ThenExitDo
I=InStr(1,String1,String2)
IfIThen
String1=Left$(String1,I-1) RepString Mid$(String1,I Len(String2))
I=I 2
DoEvents
EndIf
LoopWhileI
EndSub
□如何計算一個字符串中的行數?
FunctionCountStringLine(src_stringAsString)AsInteger
OnErrorResumeNext
Dimstring_flagAsInteger
Dimline_cntAsInteger
Dimtest_stringAsString
line_cnt=0'初始-->行數為1
string_flag=1'標志為1
test_string=src_string
DoEvents
Do
line_cnt=line_cnt 1
string_flag=InStr(test_string,vbCrLf)'判斷回車換行
test_string=Right(test_string,Len(test_string)-string_flag-1)
LoopUntilstring_flag<=0
CountStringLine=line_cnt
EndFunction
□如何從一個字符串中讀取一行字符?
FunctionReadStringLine(src_strAsString,linenoAsInteger)AsString
OnErrorResumeNext
Dimstring_flagAsInteger
Dimline_cntAsInteger
Dimtest_stringAsString
Dimret_stringAsString
line_cnt=0'初始-->行數為1
string_flag=1'標志為1
test_string=Right(src_str,2)
Iftest_string<>vbCrLfThen
test_string=src_str vbCrLf
Else
test_string=src_str
EndIf
DoEvents
Do
line_cnt=line_cnt 1
string_flag=InStr(test_string,vbCrLf)
ret_string=Left(test_string,string_flag)
test_string=Right(test_string,Len(test_string)-string_flag-1)
LoopUntillineno<=line_cnt
'Ifline_cnt=1Then
'ReadStringLine=ret_string
'Else
ReadStringLine=Left(ret_string,Len(ret_string)-1)
'EndIf
EndFunction->