How to concatenate strings

String concatenation

To concatenate strings, connect the strings with ** + (plus) ** </ font>. It is written in the same way as a mathematical formula.

In the example below, the strings ** Hello ** and ** World ** are connected.

[Example] irb


#Concatenate strings
irb(main):001:0> "Hello " + "World"
=> Hello World

Let's run the code in irb! !!

Let's concatenate the strings. Try running the code in irb as in the example below.

irb


#Concatenate strings
irb(main):001:0> "Good" + " morning"

#If it continues to be displayed like this, it is successful
=> "Good morning"

By doing so, you can concatenate the strings as above !!

Summary

** irb is a function that allows you to run Ruby programs directly from the terminal. A character string is a value for handling characters in programming. Character strings can be concatenated with + (plus) </ font>. ** **

that's all.

Recommended Posts