webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  How to search a string in a given string

    Posted Tue April 27, 2021 10:35 PM

    How to search a string in a given string. Is there any inbuilt service in webmethod integration server…??

    For example:

    I have a string input: I am a developer for local tech.
    and I have to search in the above string whether that contains ‘local’ or not.
    The search should be like ignore case.

    please suggest on same.
    Thanks in advance


    #Service-Designer
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: How to search a string in a given string

    Posted Wed April 28, 2021 02:51 AM

    Use a branch with a switch value
    Then in the label attribute of the embedded step, use /local/
    as a regex

    I often use something similar to filter for all good https responses with /^2/

    Screenshot 2021-04-28 at 08.50.19

    regards,
    John
    Product Manager
    Integration & Microservice runtime


    #Service-Designer
    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: How to search a string in a given string

    Posted Wed April 28, 2021 05:28 PM

    This variation will ignore case and be “true” if the substring “local” appears anywhere within the variable value: /(?i)local/


    #webMethods
    #Integration-Server-and-ESB
    #Service-Designer


  • 4.  RE: How to search a string in a given string

    Posted Wed April 28, 2021 05:32 PM

    Rob, which one provides better performance?
    [toLower + indexOf] or the RegEx option?

    KM


    #webMethods
    #Service-Designer
    #Integration-Server-and-ESB


  • 5.  RE: How to search a string in a given string

    Posted Wed April 28, 2021 07:25 PM

    I don’t know. I’ve never profiled these 2 approaches. I doubt the difference between them will matter in a significant way, depending upon what you’re doing. Don’t optimize prematurely – measure/profile to see if for the overall flow it is “fast enough.” If it is, you’re done. If not, then profile to see where the time is being spent and optimize that if possible. More often than not, the things that get optimized based upon opinion that it will be faster turn out to make no difference at all.


    #Service-Designer
    #webMethods
    #Integration-Server-and-ESB


  • 6.  RE: How to search a string in a given string

    Posted Wed April 28, 2021 09:40 AM

    You can use the built-in service called “indexOf” as well. This service starts the search from position 0 of the input string, unless you give it a starting position. It will only return the position of the first occurrence of the searchString “local”.

    Documentation on built-in services is here.

    So do the following if you have need to track how many times “local” is present -

    1. Calculate the length of the string “local”
    2. Since case does not matter to you, use “toLower” build-in service to get the lowercase equivalents of both the input and search strings
    3. Call indexOf and pass the input string, searchString, position (first time it will be 0)
    4. Note down the current position of searchString (i.e., “local” in your case), returned by indexOf
    5. Add the position and length values together, to calculate a new starting point (not 0th position) for the search
    6. Pass new starting position to indexOf, to get the next occurrence (this will be done using “Repeat”)
    7. Keep a track of all the positions separately (concatenate)

    Note that position will be one value less than length, numerically, so calculate the right starting point in step 5. With “encoding” values, you can use this for other languages such as Japanese, Chinese as well.

    I hope my algorithm is not confusing :slight_smile:

    KM


    #webMethods
    #Service-Designer
    #Integration-Server-and-ESB