Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

LPAD/RPAD in tMap expression

Hi,
I want to reproduce the lpad and rpad functions of SQL in a tMap expresion but I can't find the correct way to do that.
Any help would be apreciated,
Regards,
Khor
Labels (2)
8 Replies
Anonymous
Not applicable
Author

Hi Khor
You can try StringHandling.LEFT() and StringHandling.RIGHT().
Or create routine and define custom method in TOS.
Regards,
Pedro
Anonymous
Not applicable
Author

Hi pedro,
with lpad, for example if the number of characters is higher than the length of the string, it will put spaces (that's what I'm using it for). Like in this example:
lpad('ASD',9) -> 'ASD '
Would this java functions do the same, or just throw me a exception because the string is not long enough?
Thanks,
Khor.
Anonymous
Not applicable
Author

Hi
  public static String lpad(String s, int n, String replace) {
while (s.length() < n) {
s = replace+s;
}
return s;
}
public static String rpad(String s, int n, String replace) {
while (s.length() < n) {
s = s+replace;
}
return s;
}

Type this into custom routine.
Regards,
Pedro
Anonymous
Not applicable
Author

Hi pedro,
How to call this routine in tMap expression?
Regards,
Khor
Anonymous
Not applicable
Author

Hi Khor
You can find it in Expression Builder.
Regards,
Pedro
Anonymous
Not applicable
Author

Hi,
This is the first place where I lookd it for, but the routines are not there.
I have to do something to import the routines in the tMap?
Regards,
Khor
Anonymous
Not applicable
Author

Hi Khor
That means you didn't create routine correctly.
You can get more info about custom routine in document.
Regards,
Pedro
Anonymous
Not applicable
Author

Hi,
Thank for you help.
Regards,
Khor