Skip to Content
avatar image
Former Member

How to Seperate String??

Hi All,

In one of our field Name "Index_Name". we are having given value as seen in the following example.

<b><u>Source Side:</u></b>

<Index_Name>OP-A-010SCM-OP AVG CLR SPR 9.0 </Index_Name>

<Index_Name>OP-A-010SCMP-OP AVG CLR SPR 9.0 </Index_Name>

I want send the value before third one "-" in target structure like.

<b><u>Target side:</u></b>

<Index_Name>OP-A-010SCM </Index_Name>

<Index_Name>OP-A-010SCMP </Index_Name>

then how can i do that.

Thanks

Anuj

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

10 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 03, 2007 at 06:54 AM

    Some times I am getting 11 characters and some times I am getting 12 char before "-". So I coudn't use substring correct?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2007 at 06:47 AM

    Hi Anuj,

    U can use substring standard function for that

    input->subtring(0,11)->output

    try this...

    regards

    BILL

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2007 at 06:47 AM

    use <b>subString()</b> function and try ignoring rest of the string..

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 03, 2007 at 06:48 AM

    Hi,

    You can use substring of text functions in the message mapping

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 03, 2007 at 06:51 AM

    Hi,

    You can also do an User-Defined-Funtion for more powerful, for example like this:

    imports java.lang.String;

    int begin =0;

    int end = 0;

    try {

    begin = Integer.parseInt(a);

    end = Integer.parseInt(b);

    }

    catch(NumberFormatException e) { }

    return (c.substring(begin,end));

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2007 at 07:07 AM

    Anuj,

    As suggested by experts u will have to write UDF

    here is the logic

    Read your string.. when you encounter pattern '-OP' ignore rest of the string..

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2007 at 07:18 AM

    hi anuj,

    since it is variable string length you cannot use substring. what you can do is write a small UDF with the following logic

    you have to search for the occurence of "-OP" in the source string which should return the index of "-" in "-OP".

    After this you get the substring value and then you can extrace the required string.

    Hope this is helpful

    Regards

    Ramesh P

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 03, 2007 at 07:33 AM

    Hi All,

    Thanks for your reply. But always I am not getting -OP in last. some times i am getting -PL also. is it possible to count "-"??

    PL-H-AABHK00-PL

    PL-H-AADDV00-PL

    OP-A-010TRC-OP

    OP-A-010UCM-OP

    Because I have to send the value in to the target before third "-".

    I don't know the java. So can u tell me proper UDF?

    Thanks

    Anuj

    Add comment
    10|10000 characters needed characters exceeded

    • Hi anju,

      I tried with the mapping with what i sent u and it is executing successfully.

      I assume that there is only 3 "-" is your source and u want to extract the string before the thitd hypen which is going to be the last hypen.

      If this is the case this mapping will work perfectly...

      Regards

      San.

  • avatar image
    Former Member
    Oct 03, 2007 at 07:40 AM

    Hi

    This logic works for all length of source string

    public void check()

    {

    String source="OP-A-010SCMP-OP AVG CLR SPR 9.0";

    int index=source.indexOf("-OP");

    String target=source.substring(0, index);

    System.out.println(target);

    }

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 03, 2007 at 08:05 AM

    Hi Anju ,

    As refer to Monika's reply. Please change the following . It will surly help .

    -


    String source="OP-A-010SCMP-OP AVG CLR SPR 9.0";

    <b>int index=source.indexOf(" ");

    String target=source.substring(0, (index-3));</b>

    System.out.println(target);

    -


    <b>Output is :</b> OP-A-010SCMP

      • Assign points if u found helpful

      Regards.,

      V.Rangarajan

      Add comment
      10|10000 characters needed characters exceeded