cancel
Showing results for 
Search instead for 
Did you mean: 

Replace and Split

Former Member
0 Kudos

Hi All,

I have a field where in i get the input as AY;RYANBROS;HQ (the source length can vary)

now i want to remove the ; and split the ignore the source after the second occurance of ;

so for this i have written a udf taking one stirng a,

a.replaceFirst(";","").split(";")[0];

But i am getting an error as....

Source code has syntax error: /usr/sap/XD1/DVEBMGS81/j2ee/cluster/server0/./temp/classpath_resolver/Mape219e3f08c4211dc9f790018714e8238/source/com/sap/xi/tf/_IDD088_SCV_to_SAP_LOC_ORG_MM_.java:1376: not a statement a.replaceFirst(";","").split(";")[0]; ^ 1 error

I am not a java programmer..can you please help.

Rgds,

Kumar

Accepted Solutions (1)

Accepted Solutions (1)

former_member192892
Active Contributor
0 Kudos

Hi Kumar,

try this

String<i>[]</i> inputArr = input.split(";");

String output = inputArr<i>[0]</i>+inputArr<i>[1]</i>;

return output;

Former Member
0 Kudos

Hi varun

with u r code i am getting error as

/usr/sap/XD1/DVEBMGS81/j2ee/cluster/server0/./temp/classpath_resolver/Map52ba13e08c4911dc9c9c0018714e8238/source/com/sap/xi/tf/_IDD088_SCV_to_SAP_LOC_ORG_MM_.java:1381: cannot resolve symbol symbol : variable input location: class com.sap.xi.tf._IDD088_SCV_to_SAP_LOC_ORG_MM_ String[] inputArr = input.split(";"); ^ 1 error

Rgds,

Kumar

former_member192892
Active Contributor
0 Kudos

Kumar,

The input variable is the variable name u pass to ur UDF... Please provide the name which u have used in ur UDF..

former_member192892
Active Contributor
0 Kudos

I think you are using "a" as ur input variable name...

So modify the code as

String<u>[]</u> inputArr = a.split(";");

Former Member
0 Kudos

Hi Varun,

Thanks a lot...it helped.

Points awarded....to all...

Rgds,

Kumar

Former Member
0 Kudos

Hi,

This code is working fine as expected...but when ever i do not have these semi colon in the input then how to handle this situation.

Rgds,

Kumar

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Kumar

String s2 = "AY;RYANBROS;HQ";

String result = "";

String[] s3 = s2.split(";");

for (int i = 0; i < 2; i++) {

result = result + s3<i>;

}

return result;

I given i<2 because u only need first two string of ; seperation.

<b>*****rewrds point if helpfull</b>

Former Member
0 Kudos

Hi Ajay,

The input AY;RYANBROS;HQ is not same in all the cases.. it will be changing.

then how to handle this.

Rgds,

Kumar

santhosh_kumarv
Active Contributor
0 Kudos

Hi Kumar,

What is the string u need to extract for the input AY;RYANBROS;HQ.?

Regards

San

Former Member
0 Kudos

Hi

I want to remove the semi colon and also I need to ignore the data coming after the second semi colon.

Rgds,

Kumar

prabhu_s2
Active Contributor
0 Kudos

kumar

did u try this code in NWDS or in any of the java editor such as eclipse? if not check the code out there and u can get it right