迅速掌握Ruby轉(zhuǎn)義字符
作者:佚名
我們在這里為大家詳細介紹了有關(guān)Ruby轉(zhuǎn)義字符的相關(guān)用法,希望大家可以通過本文介紹的內(nèi)容深入了解Ruby語言的相關(guān)知識。
Ruby轉(zhuǎn)義字符對于一個初學(xué)Ruby語言來說是一個比較陌生的用法。在下面這篇文章中我們將會學(xué)到一些關(guān)于Ruby轉(zhuǎn)義字符的相關(guān)用法。#t#
Ruby轉(zhuǎn)義字符代碼示例:
- #! /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轉(zhuǎn)義字符的相關(guān)使用方法介紹。
責(zé)任編輯:曹凱
來源:
新浪博客