2013-12-12 32 views
0

我該如何解析兩個「%」之間的特定字符串?例如,我想從smith%john%Michael那裏得到「john」。 「%」的位置可能會更改,因爲名稱的長度可能不同。查找並解析兩個相同字符之間的字符串

+1

難道不可能性,一個字符串有三個''%和其他一些只有一個?我的意思是,你確定字符串總是有兩個'%'? – Steve

回答

1

您可以使用IndexOfLastIndexOf

Dim firstIdx = yourString.IndexOf("%") 
Dim lastIdx = yourString.LastIndexOf("%") 
Dim between = yourString.SubString(firstIdx + 1, lastIdx - firstIdx - 1) 
1
Dim firstname = "smith%john%Michael".Split("%")(1) 
'output = john 
相關問題