From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search and replace only whole strings

Solved!
Go to solution

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
(3,753 Views)

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
(3,744 Views)
Solution
Accepted by alpony01

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
(3,725 Views)

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
(3,682 Views)

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! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 5
(3,652 Views)