Get value double value from string using RegEx in vb.net

丶灬走出姿态 提交于 2019-12-13 06:13:13

问题


I have following string value which is coming from database.

str=  ">= 5.0 years"

Now from this string i want the value of double number (5.0). How can i get this value from this string?

Can any one tell me how to get the value like 5.0 from above string?

Thanks in advance.


回答1:


Try using this pattern:

PATTERN

\d+?.\d+

I'm not sure how to use regex in Visual Basic, however this C# code should help you:

C# code

string regex = @"\d+?.\d+";

string myString = ">= 5.0 years";

MatchCollection matches = Regex.Matches(myString, regex);

foreach(Match m in matches)
{
    Console.WriteLine(m);
}

Console.ReadLine();



回答2:


Maybe as simple as it is: [\d.]+ matches the floating point number



来源:https://stackoverflow.com/questions/20280428/get-value-double-value-from-string-using-regex-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!