LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

comma separated string showing on table colum

Hi
 
I have a string with comma separated.  I want to show this string on table on each colum separated by comma. Is there any easy  way I can show this.
 
i.e
 
string ==  212312,23231,sasdsa,dasdasd,sddasd
 
I want to show is on table or other control where i can separete each field. (Number of strings are coming on dynamic lines but colums are always same.)
 
 
212312            23231         sasdsa        dasdasd           sddasd
dsddsds          dsddsd       sdsdsds     dsdsds             sdsdsds
 
Thanks in advance

Message Edited by Vector on 02-10-2006 02:07 AM

0 Kudos
Message 1 of 13
(5,906 Views)

To split a string with comma-separated values, you can use Scan function, provided that you use the correct formatting string to separate each field in the input string.

To scan comma-separated numbers you can use Scan (inputString, "%d[x]%d", &num1, &num2); this example scans two number discarding the separatos, which can be any non-numeric character (comma, semicolon, tab character...). To scan strings it is necessary to know the exact separator, since the function becomes Scan (inputString, "%s[dxt44]%s", subString1, subString2); in this case "44" stands for a colon, while "59" means semicolon: it is the ascii code associated with the separator character. The separator itself is discarded via the use of "d" operator. The online help for the formatting and I/O library is very detailed on this matter to it's a good option to study it carefully.

The matter becomes considerably more difficultin case (as I can seem to understand) your input string has not always the same structure (i.e. numbers and tests are mixed in non-constant way). In this case you'll have to use a switch with a bunch of cases for each line structure you expect. In case the line structure is perfectly random, I suggest you to use the same functions reading all inputs as strings and detecting the type by using strpbrk function on each field to search for numbers.

Now the output side of your problem: you could use indifferently a table or a list box. In case your columns have not always the same type as in your example, and provided that the operator is not intended to modify directly the content of individual cells, I have found more handy a listbox. You can look at listdelx example in <cvidir>\samples\userint directory: it shows how to display elements in columns and with different colors.

In case you do prefere to use a table, you'll need to add a new row for each line of data and customize individual cells based on cell content.

Message Edited by Roberto Bozzolo on 02-10-2006 11:11 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 13
(5,882 Views)
Hi Roberto,
 
Thanks for help!!
I have always string like: (only the value will get change)
 
1,stell,abcdedf,20.4
 
Can you please help me for scan parameters. I am not able to find that detail what should i have to put in [ ].
 
Once again thanks
 
 
0 Kudos
Message 3 of 13
(5,869 Views)
To scan this string you will need to use Scan (string, "%d[x]%s[dxt44]%s[dxt44]%f", &integer, string1, string2, %double);


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 13
(5,866 Views)

Hi Roberto / All

I am not able separate comma string by using above Scan function.

Can you/Somebody help me to separate following string by using scan function.(what I have to put inside scan function)

input string : 121,abcd,11,49.11

menas : integer,string,integer,float.

Thanks a lot

0 Kudos
Message 5 of 13
(5,840 Views)

Try

Scan (string, "%d[x]%s[dxt44]%d[x]%f", &integer1, string1, &integer2, &double);

Message Edited by mvr on 02-15-2006 03:49 PM

0 Kudos
Message 6 of 13
(5,834 Views)

Hi

It is saying too many parameters.

I am not able to find what am i doing wrong. Can you please check.

Thanks for help!!

0 Kudos
Message 7 of 13
(5,829 Views)
"Too mant parameters" means that you have passed to Scan function too many variables to fill in with respect to the "%" chacters that are present in the format string. Can you post herre your actual line of code for us to check?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 13
(5,824 Views)

Hi Roberto,

Here is my code.

////////////////////////////////

int serialNo,unitNo;

double weight;

char  *partNo;

partNo = calloc(1,15);

sprintf(data,"4,abcde,21,9") ; 

Scan (data, "%d[x]%s[dxt44]%d[x]%f", &serialNo, partNo, &unitNo, &weight);

///////////////////////////

Thanks for your help!!
 
0 Kudos
Message 9 of 13
(5,824 Views)
Scan (data, "%d[x]%s[dxt44]%d[x]%f", &serialNo, partNo, &unitNo, &weight);
The highlighted "d" modifier informs Scan function to discard the corresponding field; as a result, Scan reads an integer, a string which is discarded, another integer and a double; since it is passed 4 variables to fill in instead of the expected 3, it gives that error. Put away the "d" and all will work well.
I am sorry for passing you this wrong string, anyway I strongly suggest you to read the online help for Scan and Fmt function (Formatting and I/O Library) into which you'll find this and other useful tips in using these functions.
 
With respect to "d" specifier, the online help recitates:
d Discard data When applied to a target specifier, the d modifier indicates that no target argument corresponds to the target specifier. The functions discard the data the functions would otherwise place in the target argument.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 13
(5,820 Views)