Parse string to double array
I want to be able to parse a string into a double array.
My string will have a value like so.. 101011001011.
I want to have it in the double array as {1,0,1,0,1,1,0,0,1,0,1,1}
is there a way to parse what I am looking to do?
Or does the string have to be a string array first?
Thank You in advance
Vimal KandasamyPosted Apr 27, 2009, 12:00 AM
There is a separator needed between your values.then only we can identify whether it is single digit or double digit.Else how will you identify 1220 is
1,22,0 or 12,20 or 1,2,20.
If it is single digit there is no problem.else your string should be in a format or a separator needed.
venkatesh marepalliPosted Apr 26, 2009, 12:34 AM
ur code converts only single digits.
Kirtan PatelPosted Apr 18, 2009, 10:40 AM
string str = textBox2.Text.Replace(" ","").Trim();
double[] dblArray =new double[str.Length];
int i = 0;
foreach (char c in str )
{
if (char.IsDigit(c))
{
dblArray[i] = Convert.ToDouble(c.ToString());
}
else
{
dblArray[i] = Convert.ToDouble((int)c);
}
i++;
}
This Will Convert Character Alphabets to ASCII Code too
Happy Coding :)
Thomas DodsonPosted Apr 18, 2009, 10:23 AM
Kirtan PatelPosted Apr 18, 2009, 10:08 AM
//take ArraySize = str Length
double[] dblArray =new double[str.Length];
int i = 0;
foreach (char c in str )
{
dblArray[i] = Convert.ToDouble(c.ToString());
i++;
}
Happy Coding :)