CutLeftNumber

Cuts the left part of string as long as it is number
Keeps getting characters one-by-one from left part of string until non-numeric character found.
Ignores space before or after numeric characters.
Edit 2024-07-17: Adding the dot . as acceptable number char

CodeFunctionName
What is this?

Public

Tested

Original Work
Function CutLeftNumber(StringWithNumber)
    ' Cuts the left part of string if it is number
    ' Cuts only the left part of string until non-numeric char found
    Trimmed = Trim(StringWithNumber)
    Rett = ""
    For i = 1 To Len(Trimmed)
        ASC1 = Mid(Trimmed, i, 1)
        ASC2 = Asc(ASC1)
        If (ASC2 >= 48 And ASC2 <= 57) Or ASC2 = 46 Then ' including the .
            Rett = Rett & ASC1
        ElseIf ASC1 = " " Then
            ' ignore space
        Else
            ' Any other character, break and exit
            Exit For
        End If
    Next
    CutLeftNumber = Val(Rett)
End Function

StringWithNumber

Print CutLeftNumber("120px")
120

Print CutLeftNumber(" 32490 stars found today!")
32490

Views 316

Downloads 114

CodeID
DB ID