Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
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!

 

 

14 Replies
TRF
Creator III
Creator III

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
Creator III
Creator III

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
Creator III
Creator III

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
Creator III
Creator III

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....