Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I want to split the below address from single column to multiple columns using talend.
Input
|ADDRESS|
|15 St. Patrick Rd NORTH WEST LONDON|
Expected Output
|ADDRESS_LINE1 | ADDRESS_LINE2 |
|15 St. Patrick Rd | NORTH WEST LONDON |
Hi
No a function is available for split the address based on UPPER CASE value, here I write a user routine to return the word which has all upper case character.
public class myroutine {
static String[] words;
static String currentWord="";
public static boolean isUpperCase(String s)
{
for (int i=0; i<s.length(); i++)
{
if (Character.isLowerCase(s.charAt(i)))
{
return false;
}
if(Character.isDigit(s.charAt(i)))
{
return false;
}
}
return true;
}
public static String getFirstUpperCaseWord(String address) {
words=address.split(" ");
for(int i=0;i<words.length;i++){
currentWord=words[i];
// System.out.println(currentWord);
if(isUpperCase(currentWord)==true){
break;
}
}
return currentWord;
}
}
My idea is to split the string based on the position of the first word which has all upper case character. I call the user routine on tMap and add two new columns, address1 and address2.
set the expression of address1 as:
row1.address.substring(0, row1.address.indexOf(myroutine.getFirstUpperCaseWord(row1.address)))
set the expression of address2 as:
row1.address.substring(row1.address.indexOf(myroutine.getFirstUpperCaseWord(row1.address)))
Hope it helps!
Regards
Shong