简体   繁体   English

从VBA字符串中选择特定字符

[英]Selecting a specific character from a VBA string

How do I select a specific character from a string in VBA? 如何在VBA中从字符串中选择特定字符? The strings first characters always differ but the last 6 does not. 字符串的第一个字符始终不同,但后6个字符没有差异。

Say the string is: A = 1/2'' NPT 说字符串是:A = 1/2''NPT

Here I would like to get the ' closest to 2. 在这里,我想使'最接近2。

If the string is: A = 1-1/2'' NPT 如果字符串是:A = 1-1 / 2''NPT

I would still want the ' closest to 2. 我仍然希望'最接近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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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