2017-01-25 31 views
-4

我有一個字符串像這樣如何使用正則表達式在C#中分割字符串?

"c Name David John" 

"/ . Name David John" 

"Name David John" 

我想分裂,並得到輸出爲:使用正則表達式

+0

你已經研究如何使用正則表達式做到這一點? – dfundako

+0

@dfundako是的,我做到了,但我無法得到所有類型的字符串的輸出,如上所述 – Bhargav

+0

這3種情況是每一種情況?你可以使用正則表達式來獲得「名稱」......但如果它被隨機垃圾包圍,你將無法處理所有的隨機垃圾......你需要識別每一個案例。 – SledgeHammer

回答

0

所以你只需要一個字符串David John,並宣佈一些搜索。你把你的完整字符串的子串減去你正在搜索的內容。

string SearchForThis = "Name "; 
string MyString = "Name jordan max"; 
string ResultString = MyString.Substring(MyString.IndexOf(SearchForThis) + SearchForThis.Length); 
Console.WriteLine(ResultString); 

例如:http://rextester.com/PBX95443

+0

感謝您的幫助 – Bhargav

相關問題