如何将字符串切成碎片然后将它们存储在数组中

ass*_*awy 1 vb.net arrays

在我的网站上,我有一个文本框,允许用户输入一组数字,如下所示:

(118,38,137,15,156,14,157,36,152,49,142,57)
Run Code Online (Sandbox Code Playgroud)

如何将这些数字存储在如下数组中?:

[118    38    137   15    156    14    157    36    152    49    142    57]
Run Code Online (Sandbox Code Playgroud)

Kon*_*lph 5

使用Split方法:

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

Split根据目的,该方法有几个重载.我选择了最简单的,只需要一个Character参数,在本例","c中是一个逗号.