cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting the string into two strings

Former Member
0 Kudos
94

Hi,

I am getting one string like 123/456, I need to split the string at '/' and pass 123 to one target and 456 to another. Is there any function to achieve this requirement please let me know...

Basha

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member238007
Contributor
0 Kudos

Hi,

Try this udf it works for your requirement..

String nm = "000012304/abc";

String search = "/";

String result = "";

String res = "";

int i;

i=nm.indexOf(search);

result = nm.substring(0,i);

res = nm.substring(i+1);

here nm is the input number you will be getting, search where "/" occurs and using substring read the first half and second half

regards,

Kishore

sunilchandra007
Active Contributor
0 Kudos

It can be done easily with combination of standard functions like substring, indexOf, lastIndexOf and length.

For num1 , use substring(input,0 ,indexOf(input, "/") )

For num2 , use substring(input , IndexOf(input, "/") , length(input))

Or go for UDF. You need to create 2 udf as shown below.

public String getnum1(String input, Container container)
{
String arr[] = input.split("/");
return arr[0];
}

public String getnum2(String input, Container container)
{
String arr[] = input.split("/");
return arr[1];
}

Regards,

Sunil Chandra

Former Member
0 Kudos

Hi Basha,

U cannot achive this with just built in functions.. because the substring will have only 1 parameter which is the string...

Try this UDF,One is sufficient...


public String getParts(String input,int num, Container container)
{

String tempArr[] = input.split("\\|",-1);       // that is \ \ | in quotes
return tempArr(num);

}

Now for getting first part call this UDF with input,0

for getting 2 nd part call with input,1

Babu

Edited by: hlbabu123 on May 5, 2010 4:04 PM

0 Kudos

Thanks. It solved my problem.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

Use String.Split method it will work for you.

google it for sample codes,and make it as UDF as per your requirement.,

Regards,

Raj

former_member200962
Active Contributor
0 Kudos

Use the substring function to get the before and after values.

Regards,

Abhishek.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

This is not possible without using a UDF. You must create a context type UDF with a .split on it.

Hope this helps,

Mark