cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Search and replace only whole strings

Solved!
Go to solution

Search and replace only whole strings

So i have the string: "$STEP1 AB CF $STEP10" .I want to search and replace  "$STEP1" with "XX", however when I use the "search and replace VI" ,the resulting string is "XX AB CF XX0" because the VI replaces the "$STEP1" in $STEP10 therefore giving me XX0 but my resulting string should be XX AB CF $STEP10.How do i search and replace only a whole word/string?Thank you

 

0 Kudos
Message 1 of 5
(183 Views)

Re: Search and replace only whole strings

If you know that STEP1 will always be before STEP10, and will only appear once just make sure the "replace all" is false on the search and replace function. If not you may have to do something like search for the string AND check the length before you replace.

 

Edit: Or if $STEP1 always has a space after it you can search for "$STEP1 " and replace with "XX "

0 Kudos
Message 2 of 5
(174 Views)
Highlighted
Solution
Accepted by topic author alpony01
12-06-2018 12:47 AM

Re: Search and replace only whole strings

Right-click search-and-replace and select the "Regular expression" option.  Then, instead of searching for "$STEP1", change your search string to "\$STEP1\b".

 

The leading "\" is to tell it to interpret the dollar sign literally instead of as a control character.  The trailing "\b" tell it that it needs to find a boundary at the end of the search string.  You might want to look up how regular expressions work to know more about what qualifies as a boundary.

Search and replace with regex.PNG

Message 3 of 5
(155 Views)

Re: Search and replace only whole strings

this works for me..i was using the  "\b" but the problem was that i wasn't escaping the dollar sign

0 Kudos
Message 4 of 5
(112 Views)

Re: Search and replace only whole strings

The easy answer is; make sure you replace "STEP1 ", with a space, with "XX ", also with a space. That way STEP10 won't be caught be the filter.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 5
(82 Views)