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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

Remove non-numeric charcaters from a string

Hi,
In want to keep only numeric (0 to 9) characters from a string.

I use the following code, which doesn't work.
(row2.phone_id).replaceAll( "[^\\d]", "" )
Which code should I use ?


 

Labels (2)
1 Solution

Accepted Solutions
gorotman
Creator II
Creator II

ok , probably input flow has null values in phone_id columns....may be? Is null valid for you?
You can't use replaceAll method on a null istance (of row2.phone_id).
test before call:

row2.phone_id==null?"":row2.phone_id.replaceAll( "[^\\d]", "" )

View solution in original post

5 Replies
gorotman
Creator II
Creator II

Hi, your code works (I tested it with TOS 6.2.1, tJava component and string "AAA12345BBB67890CCC").
Do you have errors or unexpected result?
_AnonymousUser
Specialist III
Specialist III
Author

Exception in component tMap_1
java.lang.NullPointerException
gorotman
Creator II
Creator II

ok , probably input flow has null values in phone_id columns....may be? Is null valid for you?
You can't use replaceAll method on a null istance (of row2.phone_id).
test before call:

row2.phone_id==null?"":row2.phone_id.replaceAll( "[^\\d]", "" )
_AnonymousUser
Specialist III
Specialist III
Author

Works fine, thanks.
gtaware
Contributor
Contributor

Just I tried like below and it worked out : 

row7.data.substring(11,19).replaceAll("[a-zA-Z]", "")