新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
迅速掌握Ruby轉(zhuǎn)義字符
Ruby轉(zhuǎn)義字符對于一個(gè)初學(xué)Ruby語言來說是一個(gè)比較陌生的用法。在下面這篇文章中我們將會學(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)使用方法介紹。
當(dāng)前題目:迅速掌握Ruby轉(zhuǎn)義字符
本文來源:http://www.dlmjj.cn/article/dhpojoe.html


咨詢
建站咨詢
