cancel
Showing results for 
Search instead for 
Did you mean: 

string separation

Former Member
0 Kudos

All,

I'm receiving a string ##FName#LName## ,I need to send FName to one field and LName to another fileds.

Please provide me with some inputs.

Thanks,

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Pushpa.

Use one UDF and two parameters one for string and the other the position,

value : String (e.g ##FName#LName)

pos : Position that you want.


String result = "";
String array01[] = value.split("##");
String array02[] = array01[1].split("#");
result = array02[pos];
return result;

Former Member
0 Kudos

Hi

You can use REGEX in the UDF to achieve this

Include 2 parameters in the UDF Say

a - [input (##Ram#Kumar##) ]

b - [Index values for first name (2) and last name (4)]

Imports: java.util.regex.*;

Parameters:

a, b


  int indexVal = Integer.parseInt(b); 
 String pattern = "(##)(.*)(#)(.*)(##)";   // first (.*) is first name - index val is 2   and last name index value is 4
 Pattern d = Pattern.compile(pattern);
 Matcher m = d.matcher(a);
            if(m.find())
            {
                a = m.group(indexVal);
              
            }

return a;

Use the same code for different fields by changing the constant(index values) in the mapping.

you can refer the below forum discussion further as srini suggest...

Regards

Ramg

Former Member
0 Kudos

You can use 2 seperate UDF to extract the 2 fields. for the leading ##, you use substring and ignore the first two values(##) and then split by #.

please use the UDF mentioned below.

use this UDF

for first name


public String StringSplit(String var1, Container container) throws StreamTransformationException{
int len = var1.length();
var1= var1.substring(2,len);
String arr[] = var1.split("#");
return arr[0];

for last name


public String StringSplit(String var1, Container container) throws StreamTransformationException{
int len = var1.length();
var1= var1.substring(2,len);
String arr[] = var1.split("#");
return arr[1];

Regards,

Srinivas

Edited by: Srinivas on Oct 12, 2010 10:59 PM