迅速掌握Ruby转义字符

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

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

Ruby转义字符代码示例:

 

 

  1. #! /usr/local/bin/ruby  
  2. # Author: xlzhu  
  3. # date: 2009-12-08  
  4. # Summary: encode string.  
  5.  
  6. class IEncoder  
  7. def initialize  
  8. end  
  9.  
  10. # Execute the given file using 
    the associate app  
  11. def run(orgStr)  
  12. str = orgStr 
  13. strstr = str.gsub('<', '&lt;')  
  14. strstr = str.gsub('>', '&gt;')  
  15. strstr = str.gsub(/['"]/, '&quot;')  
  16. strstr = str.lstrip #去掉前后空格  
  17. strstr = str.delete("\n\r") #去掉换行符  
  18. strstr = str.delete(" ")#去掉tab  
  19. puts str  
  20. end  
  21.  
  22. end 


iencoder = IEncoder.new
txt = IO.read("renderers.xml")
puts txt
iencoder.run(txt)

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

责任编辑:曹凯 来源: 新浪博客
相关推荐

2009-12-14 17:23:31

2009-12-16 10:57:16

Ruby文件锁

2009-12-18 14:19:45

Ruby on Rai

2009-12-14 16:35:28

Ruby文件行数计算

2009-12-10 14:18:22

PHP导出Word文档

2009-12-14 18:23:38

Ruby DSL测试

2010-01-12 10:19:02

VB.NET操作GDI

2010-01-11 14:28:14

VB.NET操作Exc

2009-10-29 13:38:05

VB.NET Shar

2009-12-11 16:39:08

PHP引号转义

2009-12-04 14:23:33

PHP JSON加密函

2009-12-17 14:36:57

Ruby on Rai

2009-06-28 22:56:00

虚拟化桌面虚拟化问题

2010-01-07 11:07:20

VB.NET读取INI

2009-12-16 17:31:30

Ruby on Rai

2009-08-17 17:04:29

C#转义字符

2010-07-14 15:32:21

Perl转义字符

2010-01-08 18:10:44

VB.NET实现任务栏

2009-12-14 13:19:07

Ruby字符串

2010-05-24 09:57:08

点赞
收藏

51CTO技术栈公众号