본문 바로가기

Web_Application/C#

[C#]문자열에서 실수부분만 추출



/// <summary>
/// 문자열에서 실수부분만 추출
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public string getRealNumber(string number)
{
string tempValue = "0";

try
{
Regex pattern = new Regex(@"[0-9]+(\.|\,)[0-9]+");
Match match = pattern.Match(number);

tempValue = match.Value;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

return tempValue;
}