Extract numbers inside a string
I need to extract all numbers from a string (from the left)
Example: Convert the string "bla4bla5blabla67" to number 4567
number() does not work, it gives 0 if there a letters in the string
6 Antworten
-
Hi,
I'm pretty sure, there could be shorter code, but it should work this way:
let myArray := ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
let myText := split(Text, "");
let myNumber := "";
for i in myText do
if contains(concat(myArray), i) and i != "," then
myNumber := myNumber + i
end
end;
number(myNumber)
lg, Torsten
-
Damned,
to exclude/ignore the possible "," in the string it's much easier to do:
let myArray := "0123456789";
let myText := split(Text, "");
let myNumber := "";
for i in myText do
if contains(myArray, i) then
myNumber := myNumber + i
end
end;
number(myNumber)
lg, Torsten
-
Thanks!!!
-
You can also use regex:
---
number(replacex(Text, "\D", ""))
---
Leo
-
Hello Leonid, is see that you have used the formula number(replacex(Text, "\D", "")) to remove all text from a string and leave numbers, however is there a way to remove the text from a decimal number withouth removing the decimal point? Example I have this Dimension 4.5"L and I want to remove the "L and leave the 4.5, I do not what to use the lpad or rpad or subtract options because some fields have longer number strings e.g. 456.34"L while others are as short as 4.5"L and these options create other challenges for me. Thanks for your help
-
hi. Try this:
*
number(extractx(TEXT, "\d+\.\d+"))
*
Content aside
- vor 3 JahrenZuletzt aktiv
- 6Antworten
- 1164Ansichten