05-26-2009 08:43 AM
Hi guys,
i am recieving a string from a piece of test equipment, the string contains letters and numbers, i just want the numbers but there position in the string isnt constant so i can't just spesify an offest and length.
Is there anything in the strings pallet that will extract the numbers ?
Here is an example of the string, showing the differences in length/position:
U=245.7E+0 I=0.100E+0 Watt=24.9E+0
U=245.5E+0 I=0.09E+0 Watt=25E+0
05-26-2009 08:50 AM
If you know the exact pattern of your string, then you can use the Match Pattern primitive in teh Strings pallette. Some other functions are also quite useful in things like these.
have a go thro' the Strings pallette by keeping open the LV Help.
05-26-2009 09:30 AM
Hi Zac,
using ScanFromString with a format string of "U=%f I=%f Watt=%f" should do the trick...
Another option is to use SpreadsheetStringToArray with a space as delimiter to get a !D array of strings, then use a for loop to examine the single strings, search every string for "=" and get the part after the equal sign to convert it to a number using "fractional string to number". Or you use Partha's advice. Or...
05-26-2009 10:08 AM
A trick I often use is that passing non numerical characters to the string to number function will not hurt it. But the function will stop the conversion then it find a not recognizable character. As an example if you pass 0.100E+0 Watt=24.9E+0 string to number function it will return 0.100