How to get number out of string ? E.g "Level 1" returns 1

Get help using Construct 2

Post » Sun May 03, 2015 8:50 pm

How to I strip a string retaining ONLY the numbers ?
Like "Hello-0192" returns 192.
"Level 23" returns 23.
"Level 1" returns 1.

Thanks.
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Sun May 03, 2015 9:21 pm

personally I'm not big into regex but there are regex expressions that will strip out non numeric characters. however the prolem there is guaranteeing that what is left behind is what you wanted.

if you know the string format... eg "level XX" then you have other options, You can split the text string using TOKENAT, or you can split using LEFT, MID, RIGHT. Lots of options. once you have the string subset, use INT (string) to return a numeric value.


reading the manual helps
https://www.scirra.com/manual/126/system-expressions
B
7
S
3
G
1
Posts: 184
Reputation: 1,352


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], LunaticCat and 2 guests