![]() |
|
|||||||
| 論壇說明 |
|
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
|
主題工具 | 顯示模式 |
|
|
#2 (permalink) |
|
管理版主
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
個人也對字串運用下過一份苦心
不錯用的說 比如 strTemp=StringSplit_Str("c:\abc\temp\test.txt", "1\0$\", 0) 結果strTemp="test.txt",將後面的 0 改成 1 就變成 "c:\abc\temp\" strTemp=StringSplit_Str("test.txt", "1\0$.", 0) 則可得副檔名 strTemp="txt" strTemp=StringSplit_Str("test.exe 11,22,33", ",", 2) 則strTemp= "22",改成 3 則是 "33" strText="a,b,c,d,e" strTemp=StringSplit_Str(strText, ",", 0) strTemp=StringSplit_Str(strText, ",") strTemp=StringSplit_Str(strText, ",") strTemp=StringSplit_Str(strText, ",") strTemp=StringSplit_Str(strText, ",") 則strTemp依序得到 "a" "b" "c" "d" "e" 涵式如下 =============== Public Function StringSplit_Str(ByVal TextTemp, ByVal NOStringIs, Optional ByVal StartNO As Long) Dim CharNO As Long Static no As Long If Mid$(NOStringIs, 1, 3) = "1\0" Then GoTo AgainstSearchLABLE If StartNO = 0 Then no = no + 1 StartNO = Abs(no) ElseIf StartNO > 0 Then no = 0 End If If TextTemp = "" Then Exit Function Do StartNO = StartNO - 1 CharNO = InStr(1, TextTemp, NOStringIs, vbBinaryCompare) If CharNO > 1 Then StringSplit_Str = Mid$(TextTemp, 1, CharNO - 1) ElseIf CharNO = 0 Then StringSplit_Str = TextTemp ElseIf CharNO = 1 Then StringSplit_Str = "" End If TextTemp = Mid$(TextTemp, CharNO + Len(NOStringIs)) 'trim If CharNO = 0 And StartNO <> 0 Then StringSplit_Str = "" Exit Function End If Loop Until StartNO = 0 Exit Function AgainstSearchLABLE: '逆搜尋字串 NOStringIs If TextTemp = "" Then Exit Function no = Len(TextTemp) NOStringIs = Mid$(NOStringIs, 5) CharNO = InStrRev(TextTemp, NOStringIs, no, vbBinaryCompare) CharNO = CharNO - 1 If StartNO = 1 Then '路徑 StringSplit_Str = Mid$(TextTemp, 1, CharNO + Len(NOStringIs)) ElseIf StartNO = 0 Then '檔名 StringSplit_Str = Mid$(TextTemp, CharNO + Len(NOStringIs) + 1) End If End Function |
|
|
送花文章: 2062,
|