LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting string to number

I am receiving data as string format but they are numbers is there anyway to convert them to number format? because i am trying to use comparision functuons and apparantly to make a correct comparision they have to be in number format otherwise it will give you wron results. Thank you
0 Kudos
Message 1 of 9
(36,159 Views)
To convert a string to a number you can use from the String palette the Scan from String function.
Or do you mean that the string contains the number in binary format. Then use the String to Byte array primitive to get the characters as numbers. If the numbers are of other than U8 you must use the Join Numbers primitive to get it as I16 or I32.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 2 of 9
(36,154 Views)
0 Kudos
Message 3 of 9
(36,146 Views)

Yeah i am using that function, but the problem is sometimes device sends characters and sometimes numbers and i am not sure what operation to use in "edit Scan String" because if i choose %f it can't scan the characters, i am currently using %[^ ] to scan the data.

P.S Are compariosion functions able to compare two numbers if they are in string format?

0 Kudos
Message 4 of 9
(36,143 Views)

You will need to explain a bit more. In your earlier post, you gave the example 'A= 122  B=17% C=012 '. Are you saying that you might have something like 'A= cdf  B=t% C=xyz '?.

0 Kudos
Message 5 of 9
(36,140 Views)
No , it is somtimes like A=122 B=17% ... and somtimes like A=--- B=--- , so i have combination of numbers and characters to scan what format should i use?
0 Kudos
Message 6 of 9
(36,134 Views)
No , it is somtimes like A=122 B=17% ... and somtimes like A=--- B=--- , so i have combination of numbers and characters to scan what format should i use?
0 Kudos
Message 7 of 9
(36,109 Views)
So you are having either a number or '----' only or any random character ?
 
You may need to do few steps here:
Firsat search for "A=". From the remaining string (excluding A=) search for "B=". Use the before match string output for converting to number. Use 0 as the default. Continue with "C=" from the remaining string.
 
Hope it helps
_Pradeep
0 Kudos
Message 8 of 9
(36,102 Views)
If the instrument is not returning numbers at times, you could the scan from string and format string that you already got and use the error to determine what to do. For example, you might want to just discard that reading. Wire up the error out to a case statement. Only do the comparison/plotting/whatever in the no error case. If the instrument supports such a command, you might want to query it to see why it did not return a numeric value. does the instrument manual explain what would cause this?
0 Kudos
Message 9 of 9
(36,093 Views)