1
Dim arrDetails() As String = Nothing

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

我想将此字符串拆分为

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

并使用这些值将它们插入数据库(列 - 城市、地区、州)。

我该怎么做?

谢谢

4

2 回答 2

2

你最好使用正则表达式。

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

捕获三个组。

于 2013-01-17T08:23:18.807 回答
0

这个想法是在拆分字符串时使用其他分隔符。试试这个:

string[] arr = str.Replace(", Locality:", "; Locality:").Replace(", State:", "; State:").Split(new char[] { ';' });
于 2013-01-17T08:28:23.473 回答