189 8069 5689

迅速掌握Ruby转义字符

Ruby转义字符对于一个初学Ruby语言来说是一个比较陌生的用法。在下面这篇文章中我们将会学到一些关于Ruby转义字符的相关用法。#t#

Ruby转义字符代码示例:

  1. #! /usr/local/bin/ruby
  2. # Author: xlzhu
  3. # date: 2009-12-08
  4. # Summary: encode string.
  5. class IEncoder
  6. def initialize
  7. end
  8. # Execute the given file using 
    the associate app
  9. def run(orgStr)
  10. str = orgStr
  11. strstr = str.gsub('<', '<')
  12. strstr = str.gsub('>', '>')
  13. strstr = str.gsub(/['"]/, '"')
  14. strstr = str.lstrip #去掉前后空格
  15. strstr = str.delete("\n\r") #去掉换行符
  16. strstr = str.delete(" ")#去掉tab
  17. puts str
  18. end
  19. end

iencoder = IEncoder.new
txt = IO.read("renderers.xml")
puts txt
iencoder.run(txt)

以上就是Ruby转义字符的相关使用方法介绍。


网页题目:迅速掌握Ruby转义字符
URL网址:http://www.cdxtjz.cn/article/dhpojoe.html

其他资讯