LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

removed random amount of extra spaces from string

Solved!
Go to solution

Hello i am getting a string input that sperates a data table with a random amount of spaces. 

Is there a way to replace All space sequences with a single space ?

 

e.g.

 

CPU        MEM  PID

15.689    12.2   6610

21.8         156    6611

 

(so the spaces are random)

 

I have ried replaces double spaces with single spaces a total of 8 times in succsession but for some reason that is also removing (some) single spaes as well and im not sure why.

0 Kudos
Message 1 of 3
(4,811 Views)
Solution
Accepted by Ace-Scottie

You can do this with a single Search and Replace String.  You need to enable Regular Expressions for this function (right-click the function, choose Regular Expression).  The Regular Expression " +" (space followed by a + sign) will match one or more spaces -- wire this into the Search String.  Wire a single " " (space) into the Replace String,  Set "Replace All" true, then run the function and it will replace all multiple spaces (in the current line) with a single space.  If you want it to handle multiple lines in the string, enable that option as well.

 

Bob Schor

Message 2 of 3
(4,779 Views)

"Scan string for tokens" by default treats multiple consecutive delimiters as one. That's what I would use here because it also eliminates the "spreadsheet string to array" you seem to be using later. Do it all at once!

 

 

0 Kudos
Message 3 of 3
(4,767 Views)