简体   繁体   中英

Selecting a specific character from a VBA string

How do I select a specific character from a string in VBA? The strings first characters always differ but the last 6 does not.

Say the string is: A = 1/2'' NPT

Here I would like to get the ' closest to 2.

If the string is: A = 1-1/2'' NPT

I would still want the ' closest to 2.

Any help would be appreciated! - Remi

Sub test()

    Dim myStr As String

    myStr = "A = 1/2"" NPT"

    myStr = Split(myStr, """")(0)
    myStr = Split(myStr, "= ")(1)

    MsgBox myStr

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM