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

Splitting the string into two strings

Former Member
0 Likes
416

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

View Entire Topic
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.