VB中split 函数的用法 vb里的split()函数说明
split\u51fd\u6570\u5728vb\u4e2d\u7684\u7528\u6cd5Split\u51fd\u6570\u662f\u4e00\u4e2a\u7528\u4e8e\u5206\u5272\u5b57\u7b26\u4e32\u7684\u51fd\u6570\uff0c\u5b83\u80fd\u4ee5\u4e00\u4e2a\u5b57\u7b26\u4e32\u5185\u5bb9\u4e2d\u7684\u4e00\u4e2a(\u6216\u51e0\u4e2a\u8fde\u7eed\u7684)\u7279\u5b9a\u7684\u5b57\u7b26\u4e3a\u5207\u5272\u4f4d\u70b9\u7684\u6807\u5fd7\uff0c\u5c06\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5206\u5272\u6210\u82e5\u5e72\u4e2a\u5c0f\u5b57\u7b26\u4e32\u3002\u5b83\u7684\u7528\u6cd5\u662f
\u53d8\u91cf = Split(\u539f\u5b57\u7b26\u4e32\u53d8\u91cf, \u5207\u5272\u6807\u5fd7)
\u4e0b\u9762\u7528\u4f8b\u5b50\u5177\u4f53\u8bf4\u660e\uff1a
\u8fd9\u91cc\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u53d8\u91cfa\uff0c\u5b83\u7684\u503c\u662f"\u4f60\u3001\u6211\u3001\u4ed6"\uff0c\u5219
b = Split(a, "\u3001")
\u6b64\u540eb\u5c31\u53d8\u6210\u4e86\u4e00\u4e2a\u53d8\u91cf\u7ec4\uff0cb(0)\u7684\u503c\u662f"\u4f60"\uff0cb(1)\u7684\u503c\u662f"\u6211"\uff0cb(2)\u7684\u503c\u662f"\u4ed6"\u3002
\u4e0b\u9762\u4e3e\u4e00\u4e2a\u5e94\u7528\u7684\u4f8b\u5b50\uff1aText1\u4e2d\u662f\u7528\u6587\u5b57\u8868\u793a\u7684\u6570\u636e\uff0c\u683c\u5f0f\u4e3a"\u6570\u636e1;\u6570\u636e2;\u6570\u636e3;\u2026\u2026\uff0c\u8981\u6c42\u70b9\u51fbCommand1\u540e\u5c06\u8fd9\u4e9b\u6570\u636e\u5217\u5728List1\u4e2d\u3002
Private Sub Command1_Click()
a = Split(Text1.Text, ";")
For i = 0 To UBound(a)
List1.AddItem a(i)
Next
End Sub
1. \u51fd\u6570\u89e3\u91ca\uff1a \u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u6309\u7167\u67d0\u4e2a\u5b50\u5b57\u7b26\u4e32\u5206\u5272\u6210\u5b57\u7b26\u6570\u7ec4\u3002
Function Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
Member of VBA.Strings
Split a string into an array
2. \u4f8b\u5b50
Private Sub Command1_Click()
Dim x As String
x = "a b c"
Dim y
y = Split(x, " ")
For i = 0 To UBound(y)
Debug.Print y(i)
Next
End Sub
split(目标串,切割符)得到的是一个数组。
可以在后面直接跟下标引用。 split("aaa,bbb,ccc",",")(1)得到的就是将“aaa,bbb,ccc”按照“,”切分并取出下标为1(第二个元素,vb里面下表从0开始)的元素(bbb)
Open "c:\1.txt" For Input As #1
Open "c:\2.txt" For Output As #2
While Not EOF(1)
Line Input #1, a
Print #2, Split(a, Space(1))(1) & ":" & Split(a, Space(1))(2)
Wend
Close #1
Close #2
扩展阅读:x sort reverse true ... vb中string说明和用法 ... split函数python用法 ... java中split 方法 ... vba split函数的使用方法 ... sql split 方法 ... vba split 换行符 ... vba split count ... vba 调用内置函数的方法 ...