Ruby is an extremely powerful programming/scripting language. With powerful capabilities and an efficient syntax, many things are possible with Ruby. This article explains how to compare the text that is stored in string variables in Ruby.
Things You'll Need
- Ruby interpreter
Open up any text editor, such as notepad or SciTE. We are going to compare two strings using simple equality comparison.
Type in the following code:
s = "This is my string."
s2 = "This is my other string."
The first thing we do above is assign a value to the string 's' and then a different value to the string s2. The first line beginning with puts will print out "false" because it runs a basic equality test on the two strings. These strings are not equal, so it prints false.
Save your program as 'myprogram.rb' and open up a command line prompt. Change to the directory where you saved your program and type 'ruby myprogram.rb' to see the output.
How to Create a Dictionary in Python
In the Python programming language, a dictionary is a data structure that maps unique keys to values. In other programming languages, however,...
How to Find String Length
Strings are one of the most common primitive data types from C, which implements them as character arrays to other languages, such...
How to Check if a Ruby String Has a Substring
The Ruby string class comes with dozens of built-in methods for performing common operations and queries upon strings of text. However, no...