473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to convert from String array to float array?

How do i convert my string[] to float[]?
Jul 23 '09 #1
3 14326
GaryTexmo
1,501 Expert 1GB
You'll want to run through the elements in the string array and convert them to a float... I'd suggest using float.TryParse(...) to do the conversion as well in order to have your program handle strings that aren't actually floats.

Have a look at the doc for the TryParse methods... as far as I know, all the numeric types have this method.
Jul 23 '09 #2
r035198x
13,262 8TB
Raises the question "Why the values where in a string[] in the first place?".
Don't forget to handle the cases where the string in the array might be something like "r035198x".
Jul 24 '09 #3
To convert a string to any number format you have to use Parse() function.
Following lines will make use of parse clear:

string[] str = { "1.23", "0.45", "123.4322" };
float[] flt = new float[str.Length];

for (int i = 0; i < str.Length; i++)
flt[i] = float.Parse(str[i]);


str[] is string array which contains your data. Now, to convert this data into float type we call parse function and pass string in that as parameter. If we need to convert string to int we would have used:
inte[i] = int.Parse(str[i]);

But do make sure that your string contains valid data!!!!!!
Jul 24 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jinming Xu | last post by:
Hello everyone, While embedding my C++ program with Python, I am impeded by the conversion from a Python Tuple to a C++ array. I hope to get some assistance from you guys. I have a sequence...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: Goran | last post by:
Hi! I need to convert from a unsigned char array to a float. I don't think i get the right results in the program below. unsigned char array1 = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in...
43
by: Steven T. Hatton | last post by:
http://public.research.att.com/~bs/bs_faq2.html#int-to-string Is there no C library function that will take an int and convert it to its ascii representation? The example Bjarne shows in his faq...
4
by: viks | last post by:
Hi guys I need little help here . I want to convert 'System::Object __gc * array ' to 'float array' Lets say I have object Reader with method Send ,it returns a variant that contains a...
7
by: SpreadTooThin | last post by:
I have some code... import array a = array.array('d') f = open('file.raw') a.fromfile(f, 10) now I need to convert them into floats (32 bit...) what do i do?
0
by: jeff_rowa | last post by:
Hi guyz, Could anyone please tell me how can I convert an array of floats to a string? I know that I can use this code to convert one float to a string but what is the best way for an array of...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.