Count Characters

Count the number of characters in a string, with option to exclude spaces.

Code

General
includeSpaces ? str.length : str.gsub(' ', '').length

Parameters

The string to count characters in

Whether to include spaces in the count

Server

More Ruby Snippets