String is the most commonly used class in almost all object-oriented programming languages, and is no exception in Ruby, which is documented in several common methods of string in Ruby.
Concat: Connect 2 strings, sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello". Concat ("world!") </span>
Output: Hello world!
Capitalize: Even the first letter uppercase, the other letter lowercase, example:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello world!". Capitalize () </span>
Output: Hello world!
Downcase: Convert to lowercase, sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello world!". Downcase () </span>
Output: Hello world!
UpCase: Capitalization, example:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello world!". UpCase () </span>
Output: HELLO world!
Swapcase: Case reversal, Sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello". Swapcase () </span>
Output: HELLO
Chop: Delete the character at the end, sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello World". Chop () </span>
Output: Hello worl
Hash: Get hash value, sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello world!". Hash () </span>
Output: 224243329
Next: The Last word Fugai, example:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello World". Next () </span>
Output: Hello Worle
Reverse: Reverse order, Sample:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello". Reverse () </span>
Output: Olleh
Sum: Sum the values corresponding to each character, for example:
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >puts "Hello". Sum () </span>
Output: 532
Common functions of the "Ruby Learning Note" string