2011-05-03 42 views

回答

5

阵列使用Split方法:

yourString = yourString.Substring(1, yourString.Length - 2) ' Trim parentheses. 
Dim result As String() = yourString.Split(","c) 

Split方法有几个重载,取决于目的。我在这里选择了最简单的方式,只需要一个Character参数,在这种情况下为","c,逗号。

0

String.Split

myArray = "118,38,137,15,156,14,157,36,152,49,142,57".Split (",") 
1

您可以使用正则表达式:

Dim str As string = "(118,38,137,15,156,14,157,36,152,49,142,57)" 
Dim matches As MatchCollection = New Regex(@"\d+").Matches(str) 
Dim ints As Integer() = New Integer(matches.Count - 1) } 
Dim i as Integer 
For i = 0 To ints.Length - 1 
    ints[i] = int.Parse(If(matches.Item(i).Value <> Nothing, _ 
          a.Item(i).Value, "").ToString()) 
Next