迅速掌握Ruby转义字符

我们在这里为大家详细介绍了有关Ruby转义字符的相关用法,希望大家可以通过本文介绍的内容深入了解Ruby语言的相关知识。

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

Ruby转义字符代码示例:

  • #! /usr/local/bin/ruby
  • # Author: xlzhu
  • # date: 2009-12-08
  • # Summary: encode string.
  • class IEncoder
  • def initialize
  • # Execute the given file using
    the associate app
  • def run(orgStr)
  • str = orgStr
  • str str = str.gsub(' < ', ' &lt; ')
  • str str = str.gsub(' > ', ' &gt; ')
  • str str = str.gsub(/['"]/, '&quot;')
  • str str = str.lstrip #去掉前后空格
  • str str = str.delete("\n\r") #去掉换行符
  • str str = str.delete(" ")#去掉tab
  • puts str
  • iencoder = IEncoder.new
    txt = IO.read("renderers.xml")
    puts txt
    iencoder.run(txt)

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