5/10/11

What Is an Escape Sequence?

Escape sequences in computer programming are special sets of characters that can be embedded within the text of a program to let the computer know that these characters should be interpreted differently than normal.
  • The New Line Escape Sequence

    • A common escape sequence in computer programming is "\n." When placed within a string of English text in a computer program, the characters "\n" inform the computer that it should insert a new line.

    Example

    • For example, consider the following Ruby code:

      s = "This is text \n on two lines."

      puts s

    Output

    • The output for this code will be the following:

      This is text

      on two lines.

      As you can see, the "\n" is removed and the remaining text begins on a new line.

  • No comments: