A.4 String
A.4.1 .concat (.+)
String#concat(Integer) ⇒ String
or
String#concat(String) ⇒ String
Appends the given arguments to a string. when given an integer as an argument, it converts the integer into ASCII code.
"hi".concat(33) # => "hi!""Rub".concat(121)  # => "Ruby"When given a string literal as an argument, it adds that string to the original string. .+ or + is similar to the .concat method. + will return a new combined String instead of modifying the original String. Each line of code below will give the same output.
"hi".concat(" there")
"hi".+(" there")
"hi" +(" there")
"hi" + " there"
This method returns a new String
A.4.2 * method
Multiplies the original string by the given integer and returns the new modified String.
"Ya" * 5Returns "YaYaYaYaYa"
"Ya" * 0Returns ""
A.4.3 .upcase
String#upcase ⇒ String
Converts all lowercase letters to their uppercase counterparts in the given string and returns the new modified String.
"hello".upcase`Returns
"HELLO"
A.4.4 .downcase
String#downcase ⇒ String
Converts all the uppercase letters to their lowercase counterparts from the given String. Returns the new modified String.
"HI".downcase`Returns
"hi"
A.4.5 .swapcase
String#swapcase ⇒ String
Converts all the uppercase letters to their lowercase counterparts and lowercase letters to their uppercase counterparts from the given string. Returns the new modified String.
"Hi There".swapcaseReturns
"hI tHERE"
"hI tHERE".swapcaseReturns
"Hi There"
A.4.6 .reverse (String)
String#reverse ⇒ String
Returns a new String with the characters from the original String in reverse order.
"stressed".reverseReturns
"desserts"
A.4.7 .length
String#length ⇒ Integer
Returns the Integer number of charactersin the String.
"hippopotamus".lengthReturns
12
A.4.8 .chomp
String#chomp ⇒ String
or
String#chomp(String) ⇒ String
When not given any argument, removes the "\n" (newline) character from the end of the string. When given an argument of a charcter or a string, it remove that argument from the end of the orginal string.
Returns a new String with the character removed.
"Hey!\n".chomp  
"Hey!".chomp("!")  
"Hey There".chomp("There")  
"Hey!".chomp("y")"Hey!"  
"Hey"  
"Hey "  
"Hey!"p "What is your name?"
name = gets # supposes the user inputs "Clark" and then hits return
p "Hi" + namePrints
"Hi Clark\n"
p "What is your name?"
name = gets # supposes the user inputs "Clark" and then hits return
p "Hi" + name.chompPrints
"Hi Clark"
p "What is your name?"
name = gets.chomp # supposes the user inputs "Clark" and then hits return
p "Hi" + name"Hi Clark"
A.4.9 .gsub
String#gsub(String, String) ⇒ String
Substitutes the all occurances of the first argument with the second argument in original string and returns a new String with the substitutes made.
"Hello".gsub("ello", "i")Returns
"Hi"
"Hi.there".gsub(".", " ")Returns
"Hi there"
Giving an empty string as the second arugment deletes any occurences of the first arugument in the string.
"example @ ruby.com".gsub(" ", "")Returns
"example@ruby.com"
A.4.10 .to_i (String)
String#to_i  ⇒ Integer
Converts a string literal that contains a number to an integer. The Integer is returned.
"8".to_iReturns
8
p "What is your lucky number?"
lucky_number = gets.chomp # Suppose the user types is "7" and then hits return
square = lucky_number ** 2 # This will throw an error.Returns
NoMethodError (undefined method '**' for "7":String)
This is where the .to_s method comes handy.
p "What is your lucky number?"
lucky_number = gets.chomp # Suppose the user types is "7" and then hits return
square = lucky_numbe.to_i ** 2 # This will throw an error.
p squareReturns
"49"
A.4.11 .strip
String#strip  ⇒ String
Removes all leading and trailing whitespace in the string.
Returns a new String that has been modified from the original.
"   hi there ".stripReturns
"hi there"
A.4.12 .capitalize
String#capitalize ⇒ String
Capitalizes the first character of a string.
Returns a new String that has been modified from the original.
"capitalize".capitalizeReturns
"Capitalize"
A.4.13 .split
String#split ⇒ Array
or
String#split(String) ⇒ Array
Splits a string into an substrings and creates an Array of these substrings. when not given argument, .split uses whitespace to divide the string. when given an argument, .split divides the string on that argument.
Returns an Array of the divided String.
"Hello hi byebye".splitReturns
["Hello", "hi", "byebye"]
"one!two!three!".split("!")Returns
["one", "two", "three"]
A.4.14 .include?
String#include?(String) ⇒ Boolean
Returns a boolean(true or false) based on whether the string argument is inside the string the method is being called on.
"Happy".include?("H")Returns
true
"Happy".include?("Z")Returns
false