LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/29/2009) - Search and Replace String

Another one of those personal subVI assassins today, "Search and Replace String".  One of my utility subVIs that had been sticking around removes whitespace from strings.  "Trim Whitespace.vi" came along, but it only removes whitespace from the ends (and a limited subset of whitespace at that).  With strategically chosen search strings, today's function can perform this task quite effectively.  Make sure you choose 'Regular Expression' from the right-click menu when you use it.  Now here is all it takes to start cleaning up those dirty strings.

 

SearchAndReplaceString.png 

 

VIOTD groundrules here

 

 

Message 1 of 3
(3,389 Views)
You can also use that function for cheating. I've used it, for example, to count how many lines are in a string by replacing all EOL characters with some other character and looking at the "number of replacements" output. An alternative to converting the string to an array and then getting the array size.
Message 2 of 3
(3,382 Views)

 


smercurio_fc wrote:
You can also use that function for cheating. I've used it, for example, to count how many lines are in a string by replacing all EOL characters with some other character and looking at the "number of replacements" output. An alternative to converting the string to an array and then getting the array size.

 

 

 

If that is considered cheating, then I propose a change to the rulebook.  No, wait, breaking the rules is much more fun.

Message 3 of 3
(3,373 Views)