LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan a string of "34,35.34,65,0.214,1000...." to a double arary of A[0]=34,A[1]=35.34,A[2]=65,A[3]=0.214,A[4]=1000.....

    I have a string with the format of "34,35.34,65,0.214,1000....". What I try to do is to scan this string and get the result like A[0]=34,A[1]=35.34,A[2]=65,A[3]=0.214,A[4]=1000..... Here, A is a double arrary. I expect a simple way to do this, maybe I could use fmt function, but dont's know how to do it.
 
 
Thanks!
Jacky
0 Kudos
Message 1 of 3
(3,090 Views)
I suggest you look at the "Scan/ScanFile/ScanIn Examples" topic in the CVI help. The section "String with Comma-Separated ASCII Numbers to Real Array" might be appropriate.
--
Martin
Certified CVI Developer
0 Kudos
Message 2 of 3
(3,084 Views)

Hello Jacky,

as Martin already suggested you should use the function Scan. The Scan function is used to break a string up into one or more strings, integers, doubles, ... The Fmt fuction does exact the opposite, and is used to create a string from several strings, integers, doubles, ...

Scan and Fmt use modifiers to let the user describe details about the goal and/or target arguments. The modifier you should use is [x], which is the 'discard terminator' modifier. Since you want to break up the string into doubles, use %f as the target format specifier.

I do not know how many doubles you have in your string. Suppose there are ten, then the function looks like this: Scan (string, "%s>%10f[x]", A); Since the source is a string, you can leave out the %s argument and just write Scan (string, "%10f[x]", A); You should note that the function will also expect a comma after the 10th double. If this is not the case, you should treat the 10th double seperately and write Scan (string, "%9f[x]%f", A, &A[9]);

Like Martin, I suggest you take a good look at the Scanning Functions topic in CVI Help. It's not too easy I have to admit, but you really can do a lot of things with it if you understand how it works.

Success,

Wim

0 Kudos
Message 3 of 3
(3,061 Views)