Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
ks20
Contributor III
Contributor III

How to remove special characters and unwanted text

Hello Community,

I have following values in my field, I need to remove the special characters and unwanted text in script:

Field:

185458215 (185 abc)
871541543#
526542355/452153256
Unknown
+39854662215

 

Expected Output:

185458215
871541543
526542355
Unknown  'Discard Unknown field'
39854662215


Any assistance or direction would be greatly appreciated. Many thanks

Labels (4)
1 Solution

Accepted Solutions
MayilVahanan

Hi

Its depends on the values, logic might be differ.. For your current example, try like below

Load *, Trim(if(SubStringCount(Numbers, '/'), SubField(Numbers, '/',1), if(SubStringCount(Numbers, '('), SubField(Numbers, '(',1), KeepChar(Numbers, 0123456789)))) as Numberss Inline [
Numbers
185458215 (185 abc)
871541543#
526542355/452153256
Unknown
+39854662215

];

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

5 Replies
tresesco
MVP
MVP

You can use keepchar() to retain only numbers. For cases like first value where you need to consider only the first part of the string, you can use subfield() with a separator space/ ' '.

MayilVahanan

Hi

Its depends on the values, logic might be differ.. For your current example, try like below

Load *, Trim(if(SubStringCount(Numbers, '/'), SubField(Numbers, '/',1), if(SubStringCount(Numbers, '('), SubField(Numbers, '(',1), KeepChar(Numbers, 0123456789)))) as Numberss Inline [
Numbers
185458215 (185 abc)
871541543#
526542355/452153256
Unknown
+39854662215

];

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
ks20
Contributor III
Contributor III
Author

Thank you @MayilVahanan for your prompt response. It works for me. Just a question, how does the '#' character gets discarded when we have not mentioned it in the script?

tresesco
MVP
MVP

It's like saying - 'Holiday (due to heat wave) for all except senior secondary'; not mentioning other students to come 🙂. Similarly, here keepchar() is telling to keep only numbers (0...9), rest would be discarded. 

ks20
Contributor III
Contributor III
Author

Makes sense. Thanks @tresesco 🙂