LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove multiple whitespaces from a string?

Trying to remove all spaces from this string:

240 3 0 0 0 4 2 5 1 2 3 4 5 6 7 8 4 2 34 3 12 5 240 3 0 0 0 4 2 5 1 2 3 4 5 6 7 8 4 2 34 3 12 5 2 45 23 12 54 12

This is what I have so far, and have tried other things, but can't seem to figure it out.

(input string is an output of another function)

mshaske_0-1624652021994.png

What am I missing here?

 

0 Kudos
Message 1 of 5
(1,698 Views)

Can you post what the output string should be? Based on your description the code you show, a Search and Replace function with Replace all set to TRUE a space constant for the search string and an empty string constant for the replace string, would appear to work. If I run your code with the input you provided I get the following output:

 

240300042512345678423431252403000425123456784234312524523125412

 

Is that not what you're looking for?

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 5
(1,667 Views)

You need to attach your VI with a typical input string as e.g. a diagram constant. (run once until "spreadsheet string" contains data, right-click that terminal...create constant. Attach the VI).

 

From a picture, there is no way to tell if all these spaces are really spaces or something else (e.g. tabs). How does the string look if you change the display to e.g. '\'-codes?

 

altenbach_0-1624667929256.png

 

0 Kudos
Message 3 of 5
(1,641 Views)

@Altenbach makes a very good point.  You describe the input as a "Spreadsheet string" -- if this is the output from the LabVIEW function "Array to Spreadsheet String", you will see (if you read the Help for this function) that the default delimiter between Array entries is a Tab, which looks suspiciously like a "space" on the screen, but won't be "matched" with it in a search.

 

Please, if you are having problems with your code, attach the code (as a .VI, so we can really see it, execute it, edit it, etc.).

 

Bob Schor

0 Kudos
Message 4 of 5
(1,604 Views)

This is why I often right-click the Search & Replace function and select regular expressions.  Then I use \h+ to remove all horizontal whitespace characters and not worry about distinguishing spaces and tabs.  If I also want to remove vertical whitespace characters I will use [\h\v]+.  The '+' is helpful since it will remove consecutive whitespace characters in one step instead of doing it individually.

Message 5 of 5
(1,592 Views)