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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Isolate and extract numeric values from a string and convert to int

Hi,

 

I have a string that can take the following forms:

 

"1"

"23"

"1 abcdef"

"23 abcdf"

 

I want to extract the numerical value from the string and then convert it to an int data type (as specified in output DB).

 

I have tried using the Integer.parseInt, but the job fails since the string contains non-numerical values as well. 

 

Can someone please advise me.

 

Thanks!

 

 

Labels (6)
14 Replies
TRF
Champion II
Champion II

Did you try with the following regex to remove every non-digit characters?

row1.yourField.replaceAll("\D", "")

 

Anonymous
Not applicable
Author

Thanks for your advise TRF. I overlooked one issue: The string can also take this form:

 

"1 abcdef 234"

"23 abcdef 567"

 

I only want to extract the first numbers(1 and 23). If I go head with the mentioned regex I will still be stuck with the digit-characters I don't want. 

TRF
Champion II
Champion II

If you know the value you want to extract is placed at the beginning, use this one:
row1.yourField.replaceAll(" .*$", "")
Anonymous
Not applicable
Author

I tried this but its not working. my string is like this "abc 20mbps"

manodwhb
Champion II
Champion II

Check the below expression.
row2.column==null?"":row2.column.replaceAll( "[^\\d]", "" )
Anonymous
Not applicable
Author

Thanks its works . If i have to extract mbps from the string "abc 20mbps" , how to do that?

 

Thanks in advance

manodwhb
Champion II
Champion II

You need to extract 20mbps from that string?
Anonymous
Not applicable
Author

We want to create a date variable in numeric format based on this string variable mcdvoice.

Anonymous
Not applicable
Author

no, only mbps....