cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Splitting the string into two strings

Former Member
0 Likes
415

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 Member
0 Likes

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 Likes

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 Likes

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

Former Member
0 Likes

Thanks. It solved my problem.

Former Member
0 Likes

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 Member
0 Likes

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

Regards,

Abhishek.

markangelo_dihiansan
Active Contributor
0 Likes

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