Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
We want to use a data file which contains dutch postalcode ranges. The data contains the fields Postalcode_from and Postalcode_to. These contain postalcodes like: 1234AA.
In many rows, the postalcode_from and postalcode_to are the same. However sometimes it has rangesostcode_from: 1234BB & postalcode_to: 1234BF. Now we need al the Postalcodes in this range like this (1234BB; 1234BC; 1234BD; 1234BE; 1234BF).
Anyone an idea how to do this in Talend? Any help is realy appreciated.
Thank you,
Remco
This question interested me, so I decided to give it a go. I came up with this code.....
//Inputs
String from = "1224AW";
String to = "1234CF";
//Identify components
String numFrom = from.substring(0, 4);
String firstCharFrom = from.substring(4, 5);
String secondCharFrom = from.substring(5, 6);
String numTo = to.substring(0, 4);
String firstCharTo = to.substring(4, 5);
String secondCharTo = to.substring(5, 6);
//Convert the numbers to ints
int intFrom = Integer.valueOf(numFrom).intValue();
int intTo = Integer.valueOf(numTo).intValue();
//Create an alphabet array
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
List<Character> chars = new java.util.ArrayList<>();
for (char ch : alphabet.toCharArray()) {
chars.add(ch);
}
//Calculate range values and differences
int numDifference = intTo-intFrom;
int firstCharFromVal = chars.indexOf(firstCharFrom.charAt(0));
int firstCharToVal = chars.indexOf(firstCharTo.charAt(0));
int firstCharDifference = (chars.indexOf(firstCharTo.charAt(0))) - (chars.indexOf(firstCharFrom.charAt(0)));
int secondCharFromVal = chars.indexOf(secondCharFrom.charAt(0));
int secondCharToVal = chars.indexOf(secondCharTo.charAt(0));
int secondCharDifference = (chars.indexOf(secondCharTo.charAt(0))) - (chars.indexOf(secondCharFrom.charAt(0)));
//Sort issue where a from postcode's first character is greater than the to postcode's first character.
//Example: 1234GH ---> 1235AA
if(firstCharDifference<0){
firstCharDifference = (chars.indexOf('Z')) - (chars.indexOf(firstCharFrom.charAt(0)));
}
//Sort issue where a from postcode's second character is greater than the to postcode's second character.
//Example: 1234AH ---> 1234BA
if(secondCharDifference<0){
secondCharDifference = (chars.indexOf('Z')) - (chars.indexOf(secondCharFrom.charAt(0)));
}
//Loop through numbers
for(int num = intFrom; num<=intTo; num++){
//Loop through first characters
for(int firstChar = 0; firstChar<=firstCharDifference; firstChar++){
//Loop through second characters
for(int secondChar = 0; secondChar<=secondCharDifference; secondChar++){
String postcode = num+Character.toString(chars.get((firstCharFromVal+firstChar)));
postcode = postcode+Character.toString(chars.get((secondCharFromVal+secondChar)));
//Print postcode
System.out.println(postcode);
}
secondCharFromVal = 0;
//In the last first character loop, set the second character to loop until to be the secondCharToVal
if(firstChar==(firstCharToVal-1)){
secondCharDifference = secondCharToVal;
}else{
secondCharDifference = 25;
}
}
firstCharFromVal = 0;
//In the last number loop, set the first character to loop until to be the firstCharToVal
if(num==(intTo-1)){
firstCharDifference = firstCharToVal;
}else{
firstCharDifference = 25;
}
}
Try it in a tJava as it is and it will list all postcodes between 1224AW and 1234CF. You will need to modify it to get it to work for what you want.
By the way, this is not the board for this question. I will move this question to the "Design and Development" board.