0

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

null
    • Torsten_Stang.1
    • vor 4 Jahren
    • Gemeldet - anzeigen

    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

    • Torsten_Stang.1
    • vor 4 Jahren
    • Gemeldet - anzeigen

    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

    • Claus
    • vor 4 Jahren
    • Gemeldet - anzeigen

    Thanks!!!

    • Leonid_Semik
    • vor 4 Jahren
    • Gemeldet - anzeigen

    You can also use regex:

    ---

    number(replacex(Text, "\D", ""))

    ---

    Leo

    • FiMi Hub
    • BEAMS
    • vor 2 Jahren
    • Gemeldet - anzeigen

    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

    • mirko3
    • vor 2 Jahren
    • Gemeldet - anzeigen

    hi. Try this:

    *

    number(extractx(TEXT, "\d+\.\d+"))

    *

Content aside

  • vor 2 JahrenZuletzt aktiv
  • 6Antworten
  • 1120Ansichten