Tuesday, April 28, 2009

C# Convert string to double array


Scenario
How to convert a string or a string array into a double array?
The .NET does not provide any method for us to call directly. However this is easy to implement within just a couple lines of code.

Method
//str is the input string that contains a sequence of numbers
string[] arrString = str.Split(new char[] { ' ' });//you can define your own way to split the string

double[] arrDouble = new double[arrString.Length];
for (int i = 0; i < arrString.Length; i++)
{
arrDouble[i] = double.Parse(arrString[i]);
}

comments

0 Responses to "C# Convert string to double array"

Post a Comment

BlogUpp!

 

Copyright 2009 All Rights Reserved Revolution Two Lifestyle theme by Brian Gardner | Blogger template converted & enhanced by eBlog Templates