如何从C#中最合理的字符串中选择一个子字符串,从空格到符号'#'?例如:
"Jungle #welcome to the jungle"
结果:#welcome
string originalString = "Jungle #welcome to the Juncle";
string subString = originalString.Substring(originalString.IndexOf("#"));
subString = subString.Substring(0, subString.IndexOf(" "));
使用 System.Text.RegularExpressions; Match m = Regex.Match("丛林#欢迎来到丛林", @"\s(#\w+?)\s"); Console.WriteLine(m.Captures[0].Value); // #欢迎