Ruby:String Functions

From Progzoo
Jump to: navigation, search

The methods and properties of the String type include:

s="Andrew was here"
ExampleValueComment
s+" once""Andrew was here once"The strings are concatenated using +
s == "another"FalseTests for equality - use != for not equals
s.index("was")7Returns nil if the substring is not there.
s.length15The number of characters
s.split(" ")("Andrew","was","here")Returns an array of String.
s[2..6]"drew"Characters from position 2 to 6
s.upcase"ANDREW WAS HERE"Also downcase