我循环遍历一个数组,其中有一个字符串,如下例所示:“1001--某些成分”。
现在,当我遍历数组时,我得到了整个字符串
string ingCode = theData[i + 1];但我真正需要的是简单的"1001“,而不是全部。
发布于 2010-03-11 01:22:16
您可以使用正则表达式:
Regex rgx = new Regex(@"(?<Code>\d+)--(?<Ingedient>\w+)", RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches("1001--Some Ingredient");
foreach(Match match in matches)
    Console.WriteLine("Code:{0}, Ingredient:{1}",match.Groups["Code"], match.Groups["Ingredient"]);https://stackoverflow.com/questions/2418898
复制相似问题