LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

split the lines of a string into an array and remove the parts I don't need

Solved!
Go to solution

Hello,
I'm new to labview and I have a problem dividing my string into an array and removing the parts that don't fit me

The string is (including brackets):

[
"String1",
"String2",
"String3",
"",
"",
"",
"",
"",
]

}

in this case I need to extrapolate the words and put them in a new array. also I should be able to add all the words I want. in fact the quotation marks under the words means that there could be more words

 

0 Kudos
Message 1 of 8
(3,622 Views)

Is that a single string or an array of strings? Can you post the VI you're working on?

 

As a side note: "Spreadsheet string to Array" is sometimes a good way to get an array of strings if that's what you need.

0 Kudos
Message 2 of 8
(3,614 Views)

Hi Martin,

 

what are the rules to "split the string" into "words"?

Are there always brackets? Always square brackets? Only the closing curvy bracket, but no opening bracket?

Always commas between "words"? Also always linebreaks between "words" and commas? Which kind of linebreaks?

Any rule to decide which parts "don't fit you"?

 

Most/heaviest task of "programming" is to define rules (aka algorithms)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(3,607 Views)

It is always easiest for us of you would attach a simple VI that contains a typical string as a diagram constant (now we can see the delimiters, etc.). Then tell us what result you expect after processing.

 

Is the number of lines variable or fixed?

How can we possibly know what doesn't "fit you"? What are the rules for that? (e.g. skip empty strings? words that don't start with capital S? words with less than 3 characters? words not inside double-quotes?  etc.)

0 Kudos
Message 4 of 8
(3,589 Views)

This would get you started:

String.png

Tim
GHSP
Message 5 of 8
(3,564 Views)
Solution
Accepted by topic author MartinDomix

You can use a regular expression to solve a problem like this. Assuming you're only interested in strings between double quotes the following code will extract all the non-empty strings (you can add as many strings in double quotes as you want) . If you want to get the empty strings also just replace the "+" by a "*" in the regular expression.

Get Strings.png

Ben64

 

Message 6 of 8
(3,553 Views)

regular expressions are great. I really need to learn how to use them better.

Tim
GHSP
0 Kudos
Message 7 of 8
(3,551 Views)

Hi Ben,

it was just what I needed thanks !!!

you don't know how much time I've lost for it
kudos comiiing

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