开发者

Regular Expression; extracting numbers from strings with the equals sign as the delimiter

How开发者_高级运维 can I extract the decimal part of a string that has an equals sign as the delimiter?

Example:

 2 = No
10 = (6 - 8 hrs/day, Good & Restful)
1 = low in fat 1 = low in sugar 1 = high in fiber

Someone please help. Thanks.


The following C# code will return number that is located in the left of the equal sign into an integer list given a string "input":

// string input = "<your input>";
Match m = Regex.Match(input, @"\s*(?<dec>\d+)\s*=");
List<int> intList = new List<int>();

while (m.Success)
{
    intList.Add(Int32.Parse(m.Groups["dec"].Value));
    m = m.NextMatch();
}

// Process intList
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜