字符串我具有由~~
分離元件的未定義數量的字符串,例如:分裂上的特殊字符
foobar~~some example text~~this is a string
怎樣可以將這些值分成簡單的數組,我可以然後依次通過?
我試圖用正則表達式替換~~
,所以我可以作爲一個csv工作,但必須有一個更簡單的方法?
字符串我具有由~~
分離元件的未定義數量的字符串,例如:分裂上的特殊字符
foobar~~some example text~~this is a string
怎樣可以將這些值分成簡單的數組,我可以然後依次通過?
我試圖用正則表達式替換~~
,所以我可以作爲一個csv工作,但必須有一個更簡單的方法?
string str = "foobar~~some example text~~this is a string";
string[] _result = str.Split("~~", StringSplitOptions.None);
使用Split方法
var str = "foobar~~some example text~~this is a string";
var arr = str.split('~~');
$.each(arr,function(indx,val){
console.log(val);
});
或者你可以接取像arr[0]
,arr[1]
,arr[2]
....
Ouptput
"foobar"
"some example text"
"this is a string"
您將需要使用Split
方法。您可以執行以下操作:
string[] arr=yourString.Split("~~");
foreach(string arrElement in arr)
{
//do what ever you want to
}