-6

如何从C#中最合理的字符串中选择一个子字符串,从空格到符号'#'?例如:

"Jungle #welcome to the jungle"

结果:#welcome

4

2 回答 2

3
string originalString = "Jungle #welcome to the Juncle";
string subString = originalString.Substring(originalString.IndexOf("#"));
subString = subString.Substring(0, subString.IndexOf(" "));
于 2012-04-05T18:25:40.100 回答
1
使用 System.Text.RegularExpressions;

Match m = Regex.Match("丛林#欢迎来到丛林", @"\s(#\w+?)\s");
Console.WriteLine(m.Captures[0].Value);
// #欢迎
于 2012-04-05T17:28:58.560 回答