标签:
有几个方法可选
irb(main):012:0> " \tHello \n world.\r\n ".strip
=> "Hello \n world."
irb(main):013:0> " \tHello \n world.\r\n ".lstrip
=> "Hello \n world.\r\n "
irb(main):014:0> " \tHello \n world.\r\n ".rstrip
=> " \tHello \n world."
*gsub() #用正则表达式全字符串匹配
irb(main):020:0> " \tHello \n world.\r\n ".gsub(/\s+/,‘‘)
=> "Helloworld."
irb(main):021:0> " \tHello \n world.\r\n ".gsub(‘ ‘,‘‘)
=> "\tHello\nworld.\r\n"
irb(main):023:0> " \tHello \n world.\r\n ".gsub("\n",‘‘)
=> " \tHello world.\r "
irb(main):024:0> " \tHello \n world.\r\n ".gsub("\n",‘‘).gsub("\r",‘‘)
=> " \tHello world. "
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u010713545/article/details/47041233