Skip to content

Instantly share code, notes, and snippets.

@polarstars
Created June 27, 2018 07:36
Show Gist options
  • Save polarstars/741e3fdf8aef9272c07632d7c540b8e2 to your computer and use it in GitHub Desktop.
Save polarstars/741e3fdf8aef9272c07632d7c540b8e2 to your computer and use it in GitHub Desktop.
提取字符串中的浮点数 #C#
public static double ExtractDouble(this string str)
{
Regex Reg = new Regex(@"[-+]?[0-9]*\.?[0-9]+");
Match m = Reg.Match(str);
if (m.Success)
return Convert.ToDouble(m.Value);
else
return 0.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment