2013-01-17 97 views
1
Dim arrDetails() As String = Nothing 

arrDetails = "CITY: Mumbai Thane, Locality: Bhaskar Colony, Chandanwadi, State: Maharashtra" 

我想這個字符串分割爲如何在asp.net中拆分字符串?

CITY:Mumbai Thane 
Locality:Bhaskar Colony, Chandanwadi 
State:Maharashtra 

並將其插入到數據庫 - 這些值(列市,地區,州)。

我該怎麼做?

謝謝

+0

表格的同一行中是否有多個值。意味着你想插入「Bhaskar Colony,Chandanwadi」單行嗎? –

回答

0

這個想法在分割字符串時使用了其他分隔符。只需嘗試以下操作:

string[] arr = str.Replace(", Locality:", "; Locality:").Replace(", State:", "; State:").Split(new char[] { ';' }); 
+0

謝謝namkha87! – David

2

你最好用正則表達式。

^City:([\w\s]+), Locality:([\w\s,]+), State:([\w\s]+)$ 

捕獲三組。