加载中…
个人资料
FangJinbo
FangJinbo
  • 博客等级:
  • 博客积分:0
  • 博客访问:678
  • 关注人气:30
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]VBA学习笔记之Text(六)——删除字符串中多余的空格

(2013-06-04 20:12:35)
标签:

转载

 
  • LTrim函数删除字符串前面的空格;
  • RTrim函数删除字符串后面的空格;
  • Trim函数删除字符串两头的空格(和excel中的函数Trim不同之处在于,其不能将字符串中间多余的空格删除)

     演示代码:

Sub DemoTrims()

    Dim str As String
    str = " this is     a string   to trim.          "
    Debug.Print "LTrim:", ">"; LTrim(str); "<"
    Debug.Print "RTrim:", ">"; RTrim(str); "<"
    Debug.Print "Trim:", ">"; Trim(str); "<"
    Debug.Print "Excel Trim:", ">"; _
    WorksheetFunction.Trim(str); "<"
   
End Sub
     运行结果:
LTrim:        >this is     a string   to trim.          <</DIV>RTrim:        > this is     a string   to trim.<<BR>Trim:         >this is     a string   to trim.<<BR>Excel Trim:   >this is a string to trim.<<BR>
      【应用】在字符串字符计算、字符查找、比较中经常用到。

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有