Click here to Skip to main content
13,297,411 members (65,771 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 12 Feb 2011

Unknown size Numeric Arrays from Strings - dontumindit

, 14 Feb 2011
Rate this:
Please Sign up or sign in to vote.
If size of numeric array is unknown, strings can be helpful
Often, one has to read numeric data from text files or some other file and store in numeric array, thus size of array is unknown, strings can be used in a very helpful way.

Read out all the data from file into a string, separate each numeric value by some char e.g: ('#', ' ','@' etc.)

Then use the split function to convert this string to string array.

Create dynamic array of required data type.

At last, use parse function to obtain numeric values in numeric array:

public void convert(string str)
    string[] str_arr = str.Split('#');
    double_arr = new double[str_arr.Length];
    for (int i = 0; i > str_arr.Length; i++)
        double_arr[i] = double.Parse(str_arr[i]);

Do vote and comment to improve and to help others.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pakistan Pakistan
I am a learner.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 14 Feb 2011
Article Copyright 2011 by dontumindit
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid