我希望实现这样的动作:将一个字符串中的一部分字符,换成另一个字符串。如:aaaabbbbcccc中的bbbb换成eee,注意,这两个字符串的长度有可能不一样。应该如何实现呢?最好能帮忙写一下代码,谢谢!并祝大家新年快乐!!

解决方案 »

  1.   

    Replace函数
    sub sdemo3    
    dim BT,olrstr, newstr
    BT = "<BR>"
    oldstr= "Hello"
    newstr=string(3,"-")&oldstr&string(3,"-")
    MsgBox(newstr)
    newstr = replace(newstr, oldstr, Ucase(oldstr)&" World")
    MsgBox(newstr)
    newstr = Ucase(oldstr)
    for i=0 to 1
    result =strcomp(newstr, oldstr,i)
    if result=0 then
    MsgBox(newstr &"与"&oldstr& "相等 with "&i)
    else
    MsgBox(newstr &"与"&oldstr& "不相等 with "&i)
    End if
    Next
    End sub
      

  2.   

    aalei(阿磊) ,谢谢你的代码!
    要是实现从“aabbcc”变成“aaecc"怎么实现呢?
      

  3.   

    msgbox Replace("aabbcc", "bb", "e")