有一个字符串变量,里面存放的内容和这个相似:AB1234
也就是说,都是一串字母后面再跟一串数字
现在我想在这最后一个字母和第一个数字之间加一个空格,也就是变成:AB 1234请问怎么样处理最简单呢谢谢?

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim i As Integer
        Dim strTest As String
        strTest = "ABCD123"   '假如这是测试的字符串
        For i = 1 To Len(strTest)
            If IsNumeric(Mid(strTest, i, 1)) Then Exit For '或采用如下屏蔽掉的语句来判断字符是否为数字
    '        If Asc(Mid(strTest, i, 1)) > 47 And Asc(Mid(strTest, i, 1)) < 58 Then exit for
        Next i
        If i > Len(strTest) Or i <= 1 Then Exit Sub
        strTest = Left(strTest, i - 1) & " " & Mid(strTest, i)
    End Sub
      

  2.   

    strTest = Left(strTest, i - 1) & " " & Mid(strTest, i)
    这行应该要改成
    strTest = Left(strTest, i - 1) & " " & right(strTest, len(strtest)-i+1)
    吧?
      

  3.   

    sorry
    忘了Mid(strTest, i,len(strtest)-i+1)可以写成*******.见笑了