How can we replace a string from another string in webmethods

i.e replacedVal=(“olderValue”, “newerValue”), that replaceValue should contain the newly replaced string.

You can use the following flow service found in the String folder in WmPublic package:

pub.string:replace - Replaces all occurrences of a specified substring with a substitute string.

Input Parameters:

inString String String containing the substring to replace.

searchString String Substring to replace within inString.

replaceString String Character sequence that will replace searchString. If this parameter is null or empty, the service removes all occurrences of searchString from inString.

useRegex String Optional. Flag indicating whether searchString is a regular expression. When regular expressions are used to specify a search string, replaceString may also contain interpolation variables (for example, “$1”) that match parenthetical subexpressions in searchString.
Set to:
*true to indicate that searchString is a regular expression.
*false to indicate that searchString is not a regular expression. This is the default.

Output Parameters:

value String Contents of inString with replacements made.

Refer this documentation for more details - Reverb

1 Like

Please let me know if this answers your query @sadma_khan :smiley:

I’m new in webMethods and I’m learning these things can you please tell me if i have to value = replace(“sadma”, “khan”) and replaced output should contains only khan instead of sadma then what do i have to put in those inString, searchString and replaceString ?

inStrig = Sadma Khan
searchString = Sadma
replaceString = empty. It means don’t set anything
value = Khan

Most of the built-in services’ input parameters are self explanatory. Referring the documentation helps much.

1 Like

Yeah but it only removes that sadma part from that string right but if originalStringVal=“sadmakhan” we need replace(“sadmakhan”, “sadma-khan-hello”) and the value should be value=“sadma-khan-hello”.
Then what will we do in this condition? What we’ll put in inString , searchString and replaceString?

In case, inString and searchString can be “sadmakhan” and replaceString can be “sadma-khan-hello”. Now the inputString will be replaced in output.

Please let me know if this answers your query @sadma_khan :slight_smile:

1 Like

Thanks alot this helped me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.