cancel
Showing results for 
Search instead for 
Did you mean: 

How to Seperate String??

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Then please write a userdefined function to solve the above problem.

Regards,

Sudheer.

former_member189387
Active Contributor
0 Kudos

Hi Anju Agarwal ,

I misunderstood your question . Will -op always will come at end of string ?

If so , read the string before "" space . Then find the index of -op then read the string prior to that .

Regards.,

V.Rangarajan

null

Message was edited by:

ranga rajan

Message was edited by:

ranga rajan

Former Member
0 Kudos

hi Anuj,

try this.....now u should get 11 characters only if u choose subString(0,12)

Example: substring(“Hello”, 0,1) = “H”, means that the substring from Startindex 0 to Endindex 1 (not including position 1) is shown.

Regards

BILL

santhosh_kumarv
Active Contributor
0 Kudos

Hi Anju,

try this mapping....

Name is the source node.

URL is the target node.

substring is the user defined function.

Constant should have the value "-".

Mapping: http://www.flickr.com/photos/11767150@N03/1475708348/

UDF: http://www.flickr.com/photos/11767150@N03/1475709374/

This searches for the last occurance of "-" and extract the string before it.

Regards

San

there is a Way.

Answers (9)

Answers (9)

former_member189387
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

santhosh_kumarv
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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..

iaki_vila
Active Contributor
0 Kudos

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

iaki_vila
Active Contributor
0 Kudos

Hi,

You can use substring of text functions in the message mapping

Regards.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Anuj,

U can use substring standard function for that

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

try this...

regards

BILL