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
这个词之前可能会有很多单词。
我怎样才能做到这一点?
答案 0 :(得分:1)
最简单的方法是
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);