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

Kirtan PatelRank #292 · 8.6K reputationPosted Apr 18, 2009, 6:08 AM EDT
//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 :)
Thomas Dodson3 reputationPosted Apr 18, 2009, 6:23 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Apr 18, 2009, 6:40 AM EDT
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 :)
venkatesh marepalli3 reputationPosted Apr 25, 2009, 8:34 PM EDT
ur code converts only single digits.
Vimal KandasamyRank #2,151 · 661 reputationPosted Apr 26, 2009, 8:00 PM EDT
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.