Re: Converting string to double
- From: garyusenet@xxxxxxxxx
- Date: 28 Nov 2006 07:51:06 -0800
This would rely on the garbage text that proceeds the number always
being in the same format.
I think it would be better to convert the string to a character array
and examine each character for numeric validity before adding it to the
formatted string and parsing this as a double.
I've had a go but as people familliar to this forum may know, i'm a
complete beginner. My code doesn't work as it stands, perhaps someone
could offer a modification?
private void button1_Click(object sender, EventArgs e)
{
string somestring = "? 20.00";
char[] stringarray = somestring.ToCharArray();
string formattedstring = "0";
foreach (char c in stringarray)
{
if (((int)c >= 0 && (int)c <= 9) || c == '.')
{
formattedstring += c;
}
else
{
break;
}
}
double myDouble = double.Parse(formattedstring);
MessageBox.Show(myDouble.ToString());
}
Gary.;
.
- Follow-Ups:
- Re: Converting string to double
- From: rossum
- Re: Converting string to double
- References:
- Converting string to double
- From: SMichal
- Re: Converting string to double
- From: tcomer
- Converting string to double
- Prev by Date: Display Caspol.exe -lg output in a Form TextBox
- Next by Date: Re: .NET Framework 3.0?
- Previous by thread: Re: Converting string to double
- Next by thread: Re: Converting string to double
- Index(es):