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

1 Response to "C# Convert string to double array"
  1. Rahul said...
    December 30, 2009 at 2:08 AM

    hi,

    First of all. Thanks very much for your useful post.

    I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.

    Please let me introduce you some info related to this post and I hope that it is useful for .Net community.

    There is a good C# resource site, Have alook

    http://www.csharptalk.com/2009/09/c-array.html
    http://www.csharptalk.com/2009/10/creating-arrays.html

    simi

Post a Comment

BlogUpp!

 

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