【发布时间】:2017-02-10 11:12:32
【问题描述】:
我需要取一个字符串,然后删除它的内容,包括指定短语和之后的内容,然后返回最后剩下的单词。 在这种情况下,“更多信息”。
基本上,这个脚本应该接受字符串
"Please visit
this
website
for more information if you have questions"
并返回单词"for"
(注意这只是一个例子,字符串可以是任何东西,我故意把它弄乱了换行符,因为它看起来有一半时间。)
下面的 split 方法有效,返回最后一个单词,但是 substring 方法无效。
知道我做错了什么吗?
public static string InfoParse(string input)
{
string extract = input;
extract = input.Substring(0, input.IndexOf("more information"));
extract = extract.Split(' ').Last();
return extract;
}
【问题讨论】: