Ruby/Escape Character Sequence

From Meshplex

Jump to: navigation, search
Image:Ruby_on_rails_tutorials.jpg
Ruby for complete beginners
Ruby Introduction
What can I use RoR for?
Reasons for choosing RoR over other popular programming languages such as php or asp.net .What makes Ruby so much more special
Where can I find RoR? In what “forms” does it come?
How to install RoR.Solutions for both the novice and professional programmers on Windows,Mac OS X and Linux.Prerequisites.
Ruby programming tutorials for beginners:
Ruby Basics
** Writing Programs in Ruby
** Ruby and the Text Editors
** Escape Character Sequence
** Ruby Arithmetic
** Comments in Ruby
** Ruby Documentation
Ruby Variables, Datatypes, Operators
Ruby Symbols
Ruby Statements
Ruby Converting data to another type: type conversion or typecasting
Ruby Arrays, Hashes, Ranges
Ruby Functions and built in functions
Ruby Control structures
Ruby Regular expressions and blocks
Ruby Loops
Ruby Recursion
Ruby Data Structures
Ruby Methods, Classes, Modules, Namespaces
Ruby Exceptions
Ruby Object Oriented Programming
Ruby Multithreading
Ruby File Handling.Input and Output
Ruby Basic GUI
Ruby and databases.Ruby on Rails and MySQL
Ruby Basic CGI.Using fastCGI
Ruby Basic Networking and web programming
Ruby Basic Graphics
Ajax and Rails.Web 2.0 and what it means
Ruby Testing, Debugging, Automation of tasks
Ruby Apache,Capistrano, Mongrel,lighttpd – reviews and tips
Finding a Ruby on Rails ready web hosting company
BONUS: mini tutorial for a simple RoR application

[edit] Escape character sequence

Like many other programming languages Ruby also understands the semicolons and new line characters to be the representatives to end a particular line or statement.


There are various operators such as +, -, or / when put at the end of the line, demonstrates that it is not the end but the statement still continues.


Escape Sequence Character in Ruby: There is a small list which shows few escape sequences :

1. \n : It represents a Newline

Example:

puts "this is my\nfirst Ruby Program"
Output: this is my
first Ruby Program


2. \r : It is used for Carriage return

Example:

puts "Hello\rWelcome to Ruby world"
Output:Welcome to Ruby world


3. \f : It represents Formfeed.

Example:

>> puts"ruby\fis a\fgood language"                                      
ruby is a good language                                                 
=> nil 


4. \b : It is used for Backspace.

Example:

puts "This\b\b\b\b\bIs the Ruby world"
Output:Is the Ruby world

5. \e : This denotes Escape

Example:

>> puts"ruby\elanguage\elearning"                                       
ruby�language�learning                                                  
=> nil                                                                  

6. \s : It is used to provide Space

Example:

>> puts"ruby\swelcome\slanguage"                                        
ruby welcome language                                                   
=> nil

7. \nnn : This denotes the Octal notation . Here numbers range between 0-7.


8. \x : This denotes character x


9. \t: It is used for the tab setting in programming.

Example:

puts "10\t20\t30"
Output : 10 20 30
"Tom\tDick\tHarry"
Output: Tom  Dick  Harry 
Next
Personal tools