String Replace
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Team,
I am looking to replace a particular word in a string "Home" [ Start Location] with the results in [City] and if it does not contain "home" leave it as is however i am struggling with wrapping this in a if statement with find and replace string formulae?
Solved! Go to Solution.
- Labels:
- Datasets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
IIF(StartsWith([Start Location], 'Home'),Replace([Start Location], 'Home', [City]),[Start Location])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hey @ManuelRodrigues
Something like this should work
IF Contains([Start Location], "HOME") THEN Replace([Start Location], "HOME", [City])
ELSE [Start Location] ENDIF
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
thanks @Thableaus @binuacs some of the strings have home in the middle of the string or end. sorry should have mentioned before. Would this still work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If you want to avoid surprises, you could use REGEX Match function to identify word boundaries and just replace the full word "HOME", and not pieces of it inside other words.
Example: if a word contains "HOME" like homeless, homeboy, homework, the string shouldn't be replaced, right?
So you would use word boundaries (\b)
IF REGEX_Match([Field1], ".*\bHOME\b.*") THEN Replace([Field1], "HOME", [Field2]) ELSE [Field1] ENDIF
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Don't forget the short version fuction for If ...Then ... Else ... EndIf
IIF (
Contains([Start Location], "HOME")
, Replace([Start Location], "HOME", [City])
, [Start Location]
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@Thableaus @binuacs thanks for your help and all that have also helped!
