Replace函数替代连接操作符&
来源:优易学  2011-11-1 14:21:32   【优易学:中国教育考试门户网】   资料下载   IT书店
  你大概不知道Replace函数还能这么用吧?比如下面的语句: 

    MsgBox "Disk not ready." & VBCr & vbCr & "Please check that the diskette is in the drive" & vbCr & "and that the drive’s door is closed." 

    可以看出,为了显示完整的字符串含义,要将可打印字符与非打印字符(比如:回车符vbCr)用&符号连接在一起。结果是:长长的字符连接串变得难于阅读。但是,使用Replace函数,可以巧妙地解决这个问题。方法就是:将非打印字符以字符串中不出现的一个可打印字符表示,这样完整地写出整个字符串,然后使用Replace函数替换那个特别的打印字符为非打印字符(比如:回车符vbCr)。代码如下: 
    MsgBox Replace("Disk not ready.§§Please check that the diskette is in the " & "drive§and that the drive’s door is closed.", "§", vbCr)

责任编辑:虫虫

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训