From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any string library provied by CVI?

Hi all,

  I just switch to CVI from labview. In labview coding, it is pretty easy to operate string. But in CVI, I don't find the string library. I am looking for something like "Array to Spreadsheet String". I have an array of int. The size of the array is not fixed. I have to convert each integer in the array to a string and separate each number with delimiter ",", also I need to add a given string as prefix. But in CVI, I didn't see any function like "Array to Spreadsheet String". I know something simple on C and I think I might need to allocate the variable for string first. But since the number of decimal places of each number of the array is different, how can I tell how big of string I need to allocate for the string? or is there any function or library in CVI will do the same thing like "Array to Spreadsheet String"? Thanks.

0 Kudos
Message 1 of 8
(4,617 Views)

If you are new to CVI it may worth spending some time dogging into the library menu, where yuo can find several useful resources available.

Coming to your question, there isn't a built-in equivalent to that LabVIEW VI, but you can use sprintf (from the Ansi C library) of Fmt (from the Formatting adn I/O one) with the appropriate formatting strings to obtain the same result. An additional resource can be ArrayToFile command, which directly outputs the result to a file on disk.



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 2 of 8
(4,601 Views)

I'm asking the same question. This is the type of toolkit that in my opinion should exist. Since ansi c gets messy when you need a three dimensional array of allocated pointers to manage this, there really should be a function that loads a spreadsheet table into a two dimensional array of cstring objects.

 

What is the simplest way to parse a tab deliminated spreadsheet file at the moment?

0 Kudos
Message 3 of 8
(3,790 Views)

Hi Steve_Block,

 

Are you working with Excel? LabWindows/CVI ships with a library called Excel Report (documentation attached below) which adds some functionality for interacting with Excel spreadsheets.

 

Also, I would recommend posting a new thread to the LabWindows/CVI forums, as older threads tend not to get as much exposure and are less likely to generate replies.

 

Function Tree, Excel Report: http://zone.ni.com/reference/en-XX/help/370051V-01/toolslib/toolslibexcelreport_functiontree/

Tom D.
Staff Software Engineer
NI
0 Kudos
Message 4 of 8
(3,761 Views)

I'm not working with excel in this scenario. I simply want an easy way to parse a tab deliminated text file without a huge amount of overhead allocating memory.

0 Kudos
Message 5 of 8
(3,739 Views)

Hi Steve,

 

There are currently no built in functions that can read/parse a csv file, or other delimited files, and place them into an array or table in CVI. You will need to create the array/table yourself. I recommend reading in the file as an ASCII/text file and parsing the text using tokens and storing the values into a 2D array. I also suggest formatting the string to the data type you are expecting.

 

char *strtok(char *str, const char *delim)

 

You may also want to look at the FileToArray function in CVI. You won't be able to create a 2D array but it may save a step by reading in either a single row or column in at a time.

JD B.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(3,698 Views)

Hi Steve,

based on the code provided by Nick in this discussion I created a small sample project that imports a file into a 2D array of strings. It dynamically adapts to the number of rows in the file but considers a fixed number of fields in the lines. It may be of help for you to develop the proper file parser.



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 7 of 8
(3,687 Views)

That is similar to what I did in my code, but this is the first time I've seen a 4 level pointer. I'm thinking more along the lines of a BSTR which allows you to work with a 2d array. It would be nice to have a built in object that serves as a table equivalent of a BSTR.

0 Kudos
Message 8 of 8
(3,678 Views)