2016-05-03 27 views
-2
text = "Hi, this a simple test. For more information: bla balasfafa nureahreuahre"; 

我想忽略所有的文字For more information:後,使文本將忽略一些句子畢竟文本字符串

text ="Hi, this a simple test. For more information:"; 

對我來說,問題是,我不知道在For more information:開始的索引/位置處,在字For之前可以有很多單詞。

我該如何做到這一點?要做到這一點

+3

這將是很好,如果你能告訴我們你已經嘗試到現在什麼。 – Manish

+0

根據冒號拆分字符串(:) –

+0

@sowjanyaattaluri,以及如果字符串中有更多冒號會發生什麼?這將無法正常工作... – Andrew

回答

1

simpliest方式是

string input = "Hi, this a simple test. For more information: bla balasfafa nureahreuahre"; 
string[] array = input.Split(new string[] { "For more information:" }, StringSplitOptions.RemoveEmptyEntries); 
string output = array[0] + "For more information:"; 

string input = "Hi, this a simple test. For more information: bla balasfafa nureahreuahre"; 
int lastIndex = input.LastIndexOf("For more information:"); 
var res = input.Substring(0, lastIndex + 21); 
+0

謝謝你的幫助!有用 –