Skip to content
Ruby

String API Reference

Ruby's String — a mutable sequence of bytes holding characters, with a rich set of methods.

By EZ4Code Team

String

A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters.

String#length -> Integer

Returns the number of characters in the string.

Returns: Integer

String#upcase -> String

Returns a copy of str with all lowercase letters replaced with their uppercase counterparts.

Returns: String

String#downcase -> String

Returns a copy of str with all uppercase letters replaced with their lowercase counterparts.

Returns: String

String#split(pattern=nil, [limit]) -> Array

Divides str into substrings based on a delimiter, returning an array of substrings.

Returns: Array

String#gsub(pattern, replacement) -> String

Returns a copy of str with all occurrences of pattern substituted with replacement.

Returns: String

String#strip -> String

Returns a copy of str with leading and trailing whitespace removed.

Returns: String

String#include?(substring) -> bool

Returns true if str contains the given string or character.

Returns: Boolean

String#chars -> Array

Returns an array of characters in str.

Returns: Array

More Ruby API References