LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

spliting a string using any delimiter and outputing an array

Solved!
Go to solution

Hi

 

I am trying to split a delimited string and output an array of the results.

I come from a .net background and the C# code I would use would be

 

string mystring = "mystring\r\nto\r\nsplit";

string[] myString = mystring.Split(newchar[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

 

The above code have a muli line string on the input (hence the \r\n) and output an array with the following contents

 

"mystring"

"to"

"split"

 

Additionally I would like to support comma delimited files as well.

 

I have used the string function

 

"Spreadsheet String To Array" which works well enough for comma delimted lines, but not when the delimiter is something funky like '\r\n'.

 

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

I think maybe "Match Pattern" or use the "Spreadsheet String To Array" looking for the first control character, then using "Trim Whitespace" to trim the other off the front of each element of the resulting array.  That's kind of clunky though.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 8
(4,411 Views)
Solution
Accepted by topic author JacobM123

aa.png

in vi.llb in the advanced string folder there are a few goodies that did not make it to the pallates


"Should be" isn't "Is" -Jay
Message 3 of 8
(4,408 Views)

@JÞB wrote:

aa.png

in vi.llb in the advanced string folder there are a few goodies that did not make it to the pallates


Cool!  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 8
(4,399 Views)

well that loooks good to me, it works 🙂

 

where excatly do i find that vi.llb file and where is it documented?

sounds like there may be more functions in it which might be useable,

 

are there more hidden functions stashed away somewhere if so where are they and are they documented somewhere?

 

Thanks again

0 Kudos
Message 5 of 8
(4,394 Views)

@JacobM123 wrote:

well that loooks good to me, it works 🙂

 

where excatly do i find that vi.llb file and where is it documented? 

C:\Program Files\National Instruments\LabVIEW 2012\vi.lib\AdvancedString   It is not documented anywhere in the LabVIEW help, that is one of the reasons it does not exist on the pallates

sounds like there may be more functions in it which might be useable,

 

are there more hidden functions stashed away somewhere if so where are they and are they documented somewhere?

Beware- digging through undocumented code in vi.lib should be done with care it is not for the feint of heart many of the vis found there are tested to a very specific task (like helper vi's for implementing feature set xyz) you can and probably will run across some use cases where you obtain unexpected results.  Again no published LabVIEW help but many have been the subject of community nuggets that explain their use

 

Thanks again


 

C:\Program Files\National Instruments\LabVIEW 2012\vi.lib\AdvancedString


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 8
(4,387 Views)

"Spreadsheet String to Array" works fine for multiline strings (each line terminated with \r\n).

 

Spreadsheet string.png

 

0 Kudos
Message 7 of 8
(4,377 Views)

@MIG wrote:

"Spreadsheet String to Array" works fine for multiline strings (each line terminated with \r\n).

 

Spreadsheet string.png

 


Th OP wanted to delimit the string using either a comma or an end of line. Therefore you would need to wire an array containing the various choices for the delimiter.

 

A note for the OP. In LabVIEW you need to look at teh help carefully since it doesn't always make it clear that a VI can accept various types of inputs. The Spreadsheet String to Array is polymorphic and will accept either a single string constant or an array for the delimiter.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 8 of 8
(4,359 Views)