Contents
INTRODUCTION
USING QUOTES
CREATING STRING OBJECT
ESCAPE SEQUENCE
CONVERT TO STRING
INTERATING WITH STRING
ACCESSING STRING AS ARRAY
MULTILINE STRING
VARIABLE INTERPOLATION
Introduction
Introduction
String are one of the most important data
types in computer languages.
A string is a sequence of Unicode
characters. It is a data type that stores a
sequence of data values in which
elements usually stand for characters
according to a character encoding.
String objects may be created using
String::new or as literals. When a string
appears literally in source code, it is
known as a string literal.
In Ruby string literals are enclosed by
single or double quotes.
Creating string
Creating
string
Using quotes
Using quotes
Escape sequence
Escape
sequence
Converting to string
Converting to
string
Accessing string as array
Converting to
string
Multiline string
Multiline string
Multiline string
Variable interpolation
Variable interpolation
The %s and %d are formatting characters that expect a string and a
number, respectively. The values are provided in square brackets
after the % character.
Variable interpolation is replacing variables with their values inside
string literals. To substitute a variable with a value, the variable name
is put between #{var_name} characters inside the string literal