Concatenating strings

We will need string concatenation capabilities throughout our journey in dealing with Metasploit modules. We will have multiple instances where we need to concatenate two different results into a single string. We can perform string concatenation using the + operator. However, we can elongate a variable by appending data to it using the << operator:

irb(main):007:0> a = "Nipun" 
=> "Nipun" 
irb(main):008:0> a << " loves" 
=> "Nipun loves" 
irb(main):009:0> a << " Metasploit" 
=> "Nipun loves Metasploit" 
irb(main):010:0> a 
=> "Nipun loves Metasploit" 
irb(main):011:0> b = " and plays counter strike" 
=> " and plays counter strike" 
irb(main):012:0> a+b 
=> "Nipun loves Metasploit and plays counter strike"  

We can see that we started by assigning the value "Nipun" to the variable a, and then appended "loves" and "Metasploit" to it using the << operator. We can see that we used another variable, b, and stored the "and plays counter strike" value in it. Next, we simply concatenated both of the values using the + operator and got the complete output as "Nipun loves Metasploit and plays counter strike".