几个字符串内都含有
   "COL1,COL2,COL3....COL20"有什么办法把其中的字符替换为
     "001,002,003...020"?
注明,字符串中具体包含有几个字符是不固定的!

解决方案 »

  1.   

    dim strTmp as string
    dim strNew as string
      strTmp="COL1,COL2,COL3....COL20"
      StrNew=replace(strTmp,"Col","00")如果涉及到字符不固定,用循环逐一找出替换
      

  2.   

    比较字符串,查找COL,替换为00
      

  3.   

    回复waterw(water)  但这样得到的结果是“001,002..0020"了
    我想要的结果是”001,002..020“
      

  4.   

    如果字符串格式不统一呢?
    比如,是一条sql语句呢?
      ex:"select * from aaa where col1=col11"
       要转换成"select * from aaa where  001=011"
     要怎么转换??
      

  5.   

    Sub test()
    Dim strTmp As String
    Dim strNew As String
    Dim I&, J&
        strTmp = "COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11,COL12,COL13,COL14,COL15,COL16,COL17,COL18,COL19,COL20"
        strTmp = "," & strTmp & ","
        
        I = InStr(1, strTmp, ",") + 1
        J = InStr(I, strTmp, ",") - I
        While I > 0 And J > 0
            strNew = strNew & "," & Right(Replace(Mid(strTmp, I, J), "COL", "00"), 3)
            I = InStr(I + J, strTmp, ",") + 1
            J = InStr(I + 1, strTmp, ",") - I
        Wend
        strNew = Mid(strNew, 2)
        Debug.Print strNew
    End Sub
      

  6.   

    谢谢zjcxc(邹建)
    但我的问题是如果那个字符串只包含了几个我想要替换的字符
    例子:
       ”select * from aaa where COL1=COL2+COL3+COL22"
          "select * form aaa where COL23=COL2+COL22"
    如果要把这两个语句替换成为
          ”select * from aaa where 001=002+003+022"
          "select * form aaa where 023=002+022"
    注意 替换后的字符要是三位的!COL1->001,COL11->011
      

  7.   

    不知道你是在什么情况下用。但一旦成你给的纯字符串就比较麻烦了。如果"COL1"保存在变量中的话就容易多了,先替换,在将其长度整合为3。
      

  8.   

    先把“COL”去掉转变为 SINGLE 类型,然后用 FORMAT()转变为 STRING