如下面的数据:
(0111022)中文教材要取()中的0111022如何取值了?VB中有没有可以直接取的函数?

解决方案 »

  1.   

    '得到字符串中括号里的内容
    Public Function GetKh(str As String) As String
    On Error Resume Next
        Dim intFirstLocation, intLastLocation As Integer
        intFirstLocation = InStr(1, str, "(", vbTextCompare)
        intLastLocation = InStrRev(str, ")")
        GetKh = Mid(str, intFirstLocation + 1, intLastLocation - intFirstLocation - 1)    GetKh = Trim(GetKh)End Function
      

  2.   

    Dim str As String
        
        str = "(0111022)"
        
        str = Replace(str, "(", "")
        str = Replace(str, ")", "")
        
        Debug.Print str
      

  3.   

    Up
    fj182(阿花)的方法好毒啊
      

  4.   

    两位朋友的方法还都需要完善一下,ygrobin()的方法如果字符串中有好几个括号就不适用了,fj182(阿花)的则要求括号外面不能有其他字符。
    楼主可以根据自己的需要自行修改一下。
      

  5.   

    如果字符窜中“()”是固定有的就用
    s$=Mid$(strVar,2,len(strVar)-1)
      

  6.   

    Up
    fj182(阿花)的方法好毒啊多谢夸奖。
      

  7.   

    VB中没有这个直接函数,需要自己编程。C++或VC++中有很接近的函数,几个简单语句可解决问题
      

  8.   

    阿花的改进版:
    Dim str As String
        
        str = "(0111022)(0111023)"
        
        str = Replace(str, "(", vbTab)
        str = Replace(str, ")", vbTab)
        str = Replace(str, vbTab & vbTab, vbTab)
        If Left(str, 1) = vbTab Then str = Mid(str, 2)
        If Right(str, 1) = vbTab Then str = Left(str, Len(str) - 1)    Debug.Print str其实,这样的问题最好用正则表达式。
      

  9.   

    Dim s1
       Dim s2
       Dim str         As String
       str = "(0111022)123(0111023)asda(0111024)asdas(0111024)1212)(1212)("
       
       s1 = Split(str, ")", , vbTextCompare)   
       For i = 0 To UBound(s1) - 1
           s2 = Split(s1(i), "(", , vbTextCompare)
           If UBound(s2) > 0 Then
              Debug.Print s2(UBound(s2))
           End If
       Next i
      

  10.   

    Dim str As String
    Dim str1 As String
    str = "(0111022)"str1 = Split(Split(str, "(")(1), ")")(0)
    MsgBox str1
      

  11.   

    result=split(split(str1,"(")(1),")")(0)
      

  12.   

    正则表达式:引用 Microsoft VBScript Regular Expression x.xDim re1 As RegEx, re2 As RegEx
    Dim str As String
    Dim data, num, itemstr = "(0111022)123(0111023)asda(0111024)asdas(0111024)1212)(1212)("
    str = Replace(str, "(", "(")
    str = Replace(str, ")", ")")re1.Pattern = "\(\d+\)"       '设置模板为左右括号和数字
    re1.Global = True
    Set data = re1.Execute(str)   '提取所有匹配项re2.Pattern = "[\(\)]"        '设置模板为左右括号
    re2.Global = True
    For Each item In data
        num = re2.Replace(item, "")  '消除匹配项的括号
        Debug.Print num
    Next