cas*_*One 117
你可以像这样使用IndexOf
方法和Substring
方法:
string output = input.Substring(input.IndexOf('.') + 1);
Run Code Online (Sandbox Code Playgroud)
以上没有错误处理,因此如果输入字符串中不存在句点,则会出现问题.
小智 24
你可以试试这个:
string input = "lala.bla";
output = input.Split('.').Last();
Run Code Online (Sandbox Code Playgroud)
Ita*_*aro 11
string input = "America.USA"
string output = input.Substring(input.IndexOf('.') + 1);
Run Code Online (Sandbox Code Playgroud)
我常用的扩展方法来解决这个问题:
public static string RemoveAfter(this string value, string character)
{
int index = value.IndexOf(character);
if (index > 0)
{
value = value.Substring(0, index);
}
return value;
}
public static string RemoveBefore(this string value, string character)
{
int index = value.IndexOf(character);
if (index > 0)
{
value = value.Substring(index + 1);
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
String input = ....;
int index = input.IndexOf('.');
if(index >= 0)
{
return input.Substring(index + 1);
}
Run Code Online (Sandbox Code Playgroud)
这将返回新单词。