1. Computing & Technology

Strings

How to use, process, parse and manipulate strings in Ruby.
  1. Practical Examples (4)

String Literals

The basics of strings, string interpolation, single and double quotes, escape sequences and alternate string literal syntaxes.

Getting and Printing Strings

How to read and print strings in Ruby.

Indexing Strings

When strings are used for output, they're often viewed as single immutable blocks of text. Once you form the string using string literals and interpolation, it often is simply output or stored in a variable to be output later. However, when strings are used as input, they're not usually taken at face value.

Splitting Strings

Unless user input is a single word or number, that input will need to be split, or turned into a list of strings or numbers.

String Substitution in Ruby

Splitting a string is only one way to manipulate string data. You can also make substitutions to replace one part of a string with another string. For instance, in an example string "foo,bar,baz", replacing "foo" with "boo" in "foo,bar,baz" would yield "boo,bar,baz". You can do this and many more things using the sub and gsub method in the...

String Documentation

The official documentation for Ruby's String class.

Using the 'split' Method

String manipulation using the split method in Ruby. Split strings into a list of substrings.

Using Strings

Using and manipulating strings and substrings in Ruby.

Partitioning Strings

The 'split' method is not the only fish in the sea, the 'partition' method is similar but doesn't consume the split string.

Iterating Over Strings

Iterating over a string is not a very common thing in Ruby. You have more sophisticated string tools (such as split or scan), but there are times when you'd want to iterate over the characters in a string. Unicode complicates this matter, but Ruby makes it simple.

Discuss in my forum

©2012 About.com. All rights reserved.

A part of The New York Times Company.