Lrthw exercise 10

Source: Internet
Author: User

Escape Character Table

This all of the escape sequences Ruby supports. you may not use cases of these, but memorize their format and what they do anyway. try them out in some strings to see if you can make them work.

Escape What it does.
\\ Backslash () Backslash "\"
\' Single-quote (') single quotes
\" Double-quote (") double quotation marks
\ Bell in ASCII Bell (BEL) ASCII code
\ B Space in ASCII backspace (BS) ASCII
\ F ASCII formfeed (FF)
\ N ASCII linefeed (LF)
\ R ASCII Carriage Return (CR) carriage return
\ T ASCII Horizontal tab (Tab) tab key
\ Uxxxx Character with 16-bit Hex Value xxxx (UNICODE only)
\ Uxxxxxxxx Character with 32-bit Hex Value XXXXXXXX (UNICODE only)
\ V ASCII vertical tab (VT)
\ Ooo Character with octal value OOO oo ooo
\ Xhh Character with hex value HH hexadecimal HH

Exercise code

puts "I am 6‘2\" tall." # escape double-quote inside stringputs ‘I am 6\‘2" tall.‘ # escape single-qoute inside stringtabby_cat = "\tI‘m tabbled in."persian_cat = "I‘m splite\non a line."backslash_cat = "I‘m \\a \\ cat."fat_cat = """I‘ll do a list:\t* Cat food\t* Fishies\t* Catnip\n\t* Grass"""puts tabby_catputs persian_catputs backslash_catputs fat_cat

Result:

[[email protected] day4]$ ruby ex10.rb I am 6‘2" tall.I am 6‘2" tall.    I‘m tabbled in.I‘m spliteon a line.I‘m \a \ cat.I‘ll do a list:    * Cat food    * Fishies    * Catnip    * Grass

Use three single quotes ('') instead of three double quotes (""")

read_list = ‘‘‘this is new year\‘s read list(just maybe, not very sure, I guess...)\t* Camille\t* Madame Bovary\t* The Red and the Black\t* True Blood‘‘‘

The result is as follows:

this is new year‘s read list(just maybe, not very sure, I guess...)\t* Camille\t* Madame Bovary\t* The Red and the Black\t* True Blood

It is displayed as is, which is also the difference between double quotation marks and single quotation marks used in strings.

 

Lrthw exercise 10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.