Left/Right/Mid (1 Viewer)

prasadgov

Member
Local time
Today, 06:59
Joined
Oct 12, 2021
Messages
43
TIA,

How to get just the value, 50000000 from /FAMT/50000000,
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:59
Joined
Sep 21, 2011
Messages
14,713
Use InstrRev() and Right()
Or you could use Split() but that would involve several lines of code.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:59
Joined
May 21, 2018
Messages
8,748
Code:
mid(x, InStrRev(x, "/") + 1)
 

plog

Banishment Pending
Local time
Today, 05:59
Joined
May 11, 2011
Messages
11,724
We'd need more examples to make a valid general algorithm. Is it always after the 2nd slash? Could there be extra characters after it?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:59
Joined
Feb 28, 2001
Messages
27,621
If there is a format rule for that field such that the number you want is ALWAYS last, then MajP's suggestion is probably easiest and most direct. If there are variations to consider, we would need to know them all.
 

prasadgov

Member
Local time
Today, 06:59
Joined
Oct 12, 2021
Messages
43
We'd need more examples to make a valid general algorithm. Is it always after the 2nd slash? Could there be extra characters after it?
No extra characters after that. That is how the data comes in always.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:59
Joined
Feb 28, 2001
Messages
27,621
Wouldn't Val return the correct value? Not sure if the slashes would interfere.

'Fraid not, Dave. "The Val function stops reading the string at the first character that it can't recognize as part of a number."


I think that if it is always \xxxx\number then the InStrRev suggestion from MajP is best.
 

MarkK

bit cruncher
Local time
Today, 03:59
Joined
Mar 17, 2004
Messages
8,210
If the prefix is always "/FAMT/" then use...
Code:
Mid([fieldname], 7)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:59
Joined
May 7, 2009
Messages
19,268
you can also use RegExp:
Code:
' chatgpt
Function ExtractNumbers(inputString As String) As String
    Dim regex As Object
    Set regex = CreateObject("VBScript.RegExp")
    
    Dim matches As Object
    Dim match As Object
    Dim result As String
    
    ' Regular expression pattern to match numbers (including decimals)
    regex.Pattern = "\b\d+(\.\d+)?\b"
    regex.Global = True
    regex.IgnoreCase = True
    
    ' Check if there are matches
    If regex.Test(inputString) Then
        ' Get all matches
        Set matches = regex.Execute(inputString)
        
        ' Build the result string from matches
        For Each match In matches
            result = result & match.Value & " "
        Next match
        
        ' Remove trailing space
        result = Trim(result)
    End If
    
    ExtractNumbers = result
End Function

?ExtractNumbers("/FAMT/50000000,")
result: 50000000
 

Users who are viewing this thread

Top Bottom