Re: Converting string to double



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.;

.