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
Expand all | Collapse all

How to replace the first occurenace of .

  • 1.  How to replace the first occurenace of .

    Posted Mon July 12, 2010 12:21 PM

    Hi All,

    Can you please give me the flow code to replace first occurance of the character(dot).

    Cheers,
    Sasanka


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 2.  RE: How to replace the first occurenace of .

    Posted Tue July 13, 2010 04:47 AM

    You could do this in a couple ways in Flow service but again that will need to invoke a few java services instead you can use one Java method called String.replace() in a java service to replace the first occurence.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: How to replace the first occurenace of .

    Posted Tue July 13, 2010 06:45 AM

    find the first occurance using pub.string.indexOf service,then use pub.string.replace to replace the string


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 4.  RE: How to replace the first occurenace of .

    Posted Tue July 13, 2010 08:00 AM

    I believe pub.String.replace service replaces all the occurrences of the searchString in v6.5, not sure in later versions.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 5.  RE: How to replace the first occurenace of .

    Posted Tue July 13, 2010 08:17 AM

    Ok , If it has to be using flow services then you need to break the string with the first occurence of the DOT as the breaking point at the same time with the DOT included in the first part and use replace service on the first part only and then concat them. You will have only the first occurrence replaced.

    A pseudo code of the above logic, you can built this is in wM Flow itself.

     
    inputString = "ab.cd.ef.gh";
    Str1 = inputString.substring(0, inputString.indexOf(“.”)+1);
    Str2 = inputString.substring(inputString.indexOf(“.”)+2, inputString.length);
    Str1 = Str1.replace(“.”, “x”);
    outString = Str1 + Str2;

    Sure there would be other ways also to do this.

    -HTH


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 6.  RE: How to replace the first occurenace of .

    Posted Tue July 13, 2010 04:53 PM

    Use pub.string:replace and a regex to select the first occurring ‘.’ character. I’m not sure what the regex would be.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: How to replace the first occurenace of .

    Posted Tue July 20, 2010 06:19 PM

    reamon right, use built-in replace with regex.
    1st string identified by ^,
    last string identified by $,
    special character, such as . and +, should appended with prefix \

    so to replace first ., search by ^. with regex true

    but, if the .(dot) not in the first char of string, you cant use the built-in replace,
    use java service with method of replaceFirst.

    String s = “testt…a”;
    s = s!=null?s.replaceFirst(“\.”, “[newChar]”):null;


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 8.  RE: How to replace the first occurenace of .

    Posted Tue July 20, 2010 10:11 PM

    Not quite accurate.

    ^ is the beginning of the string, not the first occurrence.
    $ is the end of the string, not the last occurrence.

    ^. will work only if . is the first character (as you mention).

    Here are the inputs that will do the work with pub.string:replace

    inString: the.quick.brown.fox
    searchString: .(.*)
    replaceString: #$1
    useRegex: true

    The output will be the#quick.brown.fox

    I’m not sure how efficient that will be for a lengthy string but it does the job.

    Of course you create your own Java service as suggested, but at least there is an option to leverage what already exists.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 9.  RE: How to replace the first occurenace of .

    Posted Wed July 21, 2010 03:05 PM

    about the ^ and the $, its my bad of sentence. but i mean the same.
    and thank for correcting the built-in replace string service


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services