迅速掌握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
- 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轉義字符的相關使用方法介紹。
責任編輯:曹凱
來源:
新浪博客