迅速掌握Ruby轉(zhuǎn)義字符
作者:佚名
我們?cè)谶@里為大家詳細(xì)介紹了有關(guān)Ruby轉(zhuǎn)義字符的相關(guān)用法,希望大家可以通過(guò)本文介紹的內(nèi)容深入了解Ruby語(yǔ)言的相關(guān)知識(shí)。
Ruby轉(zhuǎn)義字符對(duì)于一個(gè)初學(xué)Ruby語(yǔ)言來(lái)說(shuō)是一個(gè)比較陌生的用法。在下面這篇文章中我們將會(huì)學(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é)任編輯:曹凱
來(lái)源:
新浪博客