- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compare the content of two StringBuilders
Equals method is used in C# to compare the content of two StringBuilders.
The following are our two StringBuilders −
// first StringBuilder str1 = new StringBuilder(); str1.Append("Tim"); str1.Append("Tom"); str1.Append("Henry"); // second StringBuilder str2 = new StringBuilder(); str2.Append("John"); str2.Append("David"); str2.Append("Beth");
Now use the Equals() method to compare both the methods −
if (str1.Equals(str2)) { Console.WriteLine("Contents are equal!"); }
The following is the complete code −
Example
using System; using System.Text; class Demo { static void Main() { // first StringBuilder str1 = new StringBuilder(); str1.Append("Tim"); str1.Append("Tom"); str1.Append("Henry"); // second StringBuilder str2 = new StringBuilder(); str2.Append("John"); str2.Append("David"); str2.Append("Beth"); // check for equality if (str1.Equals(str2)) { Console.WriteLine("Contents are equal!"); } else { Console.WriteLine("Contents are unequal!"); } } }
Output
Contents are unequal!
- Related Articles
- Compare the two Strings lexicographically in Java
- Compare two objects of Character type in Java
- Compare two Strings in Java
- Compare Two Java long Arrays
- Compare Two Java double arrays
- How do we compare the elements of two lists in Python?
- Compare two arrays of single characters and return the difference? JavaScript
- Compare two strings lexicographically in C#
- Java Program to compare two sets
- Compare two strings lexicographically in Java.
- Java Program to Compare Two Strings
- Compare two file paths in Java
- PHP program to compare two dates
- To compare the emf of two given primary cells using potentiometer experiment
- Subtract content of two ports by interfacing 8255 with 8085 microprocessor

Advertisements