首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么提取字符串中的所有子字符串到数组

2012-02-26 
如何提取字符串中的所有子字符串到数组字符串用几种符号一起做分割符比如说:有这样一个字符串:”ndjk,dshjd

如何提取字符串中的所有子字符串到数组
字符串用几种符号一起做分割符  
比如说:有这样一个字符串:”ndjk,dsh   jdks?bhsj   123,abc”  
要分成4个数组元素   而不是2个


[解决办法]
修改了下:
Dim mystr As String
Dim nLoop As Integer
Dim lastpos As Integer
Dim output(3) As String
Dim nowoutput As Integer

mystr = "ndjk,dsh jdks?bhsj 123,abc "
lastpos = 1
For nLoop = 1 To Len(mystr)
If Mid(mystr, nLoop, 1) = ", " Or Mid(mystr, nLoop, 1) = "? " Then
output(nowoutput) = Mid(mystr, lastpos, nLoop - lastpos)
lastpos = nLoop + 1
nowoutput = nowoutput + 1
End If
Next nLoop
output(3) = Mid(mystr, lastpos, Len(mystr) - lastpos + 1)
[解决办法]
太复杂了,简单的如这样:

s= "ndjk,dsh jdks?bhsj 123,abc "
s=replace(s, "? ", ", ")
s=replace(s, "/ ", ", ")
s=replace(s, "\ ", ", ")
s=replace(s, "; ", ", ")
s=replace(s, "| ", ", ")

'若干种都可以,添加转换就是。

dim arr() as string
arr=split(s, ", ")



————————————————————————————————————
现在的人们要求越来越高!事情还是十画还没有一撇,就要源码!

热点排行