Ruby转义字符对于一个初学Ruby语言来说是一个比较陌生的用法。在下面这篇文章中我们将会学到一些关于Ruby转义字符的相关用法。#t#
Ruby转义字符代码示例:
- #! /usr/local/bin/ruby
- # Author: xlzhu
- # date: 2009-12-08
- # Summary: encode string.
- class IEncoder
- def initialize
- end
- # Execute the given file using
the associate app - def run(orgStr)
- str = orgStr
- strstr = str.gsub('<', '<')
- strstr = str.gsub('>', '>')
- strstr = str.gsub(/['"]/, '"')
- strstr = str.lstrip #去掉前后空格
- strstr = str.delete("\n\r") #去掉换行符
- strstr = str.delete(" ")#去掉tab
- puts str
- end
- end
iencoder = IEncoder.new
txt = IO.read("renderers.xml")
puts txt
iencoder.run(txt)
以上就是Ruby转义字符的相关使用方法介绍。