Can Strings Be Compared In C++? Absolutely! At compare.edu.vn, we provide the solutions to explore how C++ enables you to compare strings using various methods, providing flexibility and control over your string comparisons. Dive into this guide to understand the nuances of string comparison, enhance your coding skills, and make informed decisions. String comparison in C++ involves assessing strings for equality, inequality, or lexicographical order, and you’ll find out how to use comparison operators and standard library functions.
1. Introduction to String Comparison in C++
String comparison is a fundamental operation in C++ programming, essential for tasks ranging from data validation to sorting algorithms. Understanding how to effectively compare strings is crucial for writing robust and efficient code. C++ offers several methods for string comparison, each with its own advantages and use cases. This comprehensive guide delves into the various techniques available, providing clear explanations and practical examples to help you master string comparison in C++. You’ll learn about relational operators, the compare()
function, and how to choose the best approach for your specific needs.
1.1. Why is String Comparison Important?
String comparison is vital in numerous programming scenarios. Here are a few key reasons why:
- Data Validation: Verifying user input to ensure it matches expected formats or values. For example, checking if an entered email address contains the “@” symbol and a domain.
- Sorting: Arranging strings in a specific order, such as alphabetical sorting of names or sorting files by their filenames.
- Searching: Locating specific strings within a larger body of text, like finding a keyword in a document.
- Authentication: Comparing entered passwords with stored values to authenticate users.
- Configuration: Matching configuration settings against predefined values to control application behavior.
1.2. Overview of String Comparison Methods in C++
C++ provides several ways to compare strings:
- Relational Operators: Using operators like
==
,!=
,>
,<
,>=
, and<=
to compare strings. std::string::compare()
: A member function of thestd::string
class that offers more detailed comparison options, including substring comparisons.
Each method has its own strengths and weaknesses. Relational operators are straightforward for simple equality and inequality checks, while compare()
provides greater flexibility for more complex scenarios.
1.3. What this Guide Will Cover
This guide will cover the following topics in detail:
- Understanding C++ Strings: A brief overview of the
std::string
class. - Using Relational Operators: Comparing strings using
==
,!=
,>
,<
,>=
, and<=
. - Using
std::string::compare()
: Exploring thecompare()
function and its various parameters. - Comparing Substrings: Using
compare()
to compare specific parts of strings. - Case Sensitivity: How to perform case-sensitive and case-insensitive string comparisons.
- Performance Considerations: Comparing the performance of different string comparison methods.
- Best Practices: Recommendations for writing clean, efficient, and maintainable string comparison code.
- Common Pitfalls: Avoiding common mistakes when comparing strings.
- Practical Examples: Real-world examples of string comparison in action.
- Advanced Techniques: Exploring more advanced string comparison techniques and algorithms.
2. Understanding C++ Strings
Before diving into string comparison methods, it’s essential to have a solid understanding of the std::string
class in C++.
2.1. The std::string
Class
The std::string
class is part of the C++ Standard Library and provides a powerful and flexible way to work with strings. It offers numerous advantages over traditional C-style character arrays, including automatic memory management, dynamic resizing, and a rich set of member functions.
2.2. Key Features of std::string
- Dynamic Size:
std::string
objects can grow or shrink as needed, eliminating the need to manually manage memory allocation. - Member Functions: The class provides a wide range of member functions for manipulating strings, such as
append()
,insert()
,erase()
,find()
, andsubstr()
. - Operator Overloading:
std::string
overloads various operators, including=
,+
,[]
, and relational operators, making string manipulation more intuitive. - Unicode Support:
std::string
can handle Unicode characters, allowing you to work with text from different languages.
2.3. Creating and Initializing std::string
Objects
You can create and initialize std::string
objects in several ways:
-
Default Constructor: Creates an empty string.
std::string str1; // Empty string
-
Copy Constructor: Creates a new string as a copy of an existing one.
std::string str2 = "Hello"; std::string str3 = str2; // str3 is a copy of str2
-
String Literal: Initializes a string with a string literal.
std::string str4 = "World";
-
Character Array: Initializes a string with a C-style character array.
const char* charArray = "C++ String"; std::string str5 = charArray;
-
Substring: Creates a string from a portion of another string.
std::string str6 = str5.substr(4, 6); // str6 is "String"
2.4. Basic String Operations
Before comparing strings, let’s review some basic string operations:
-
Concatenation: Joining two or more strings together using the
+
operator or theappend()
function.std::string str7 = "Hello"; std::string str8 = "World"; std::string result = str7 + " " + str8; // result is "Hello World" str7.append(" "); str7.append(str8); // str7 is now "Hello World"
-
Accessing Characters: Accessing individual characters in a string using the
[]
operator or theat()
function.std::string str9 = "Example"; char firstChar = str9[0]; // firstChar is 'E' char secondChar = str9.at(1); // secondChar is 'x'
-
Length: Getting the length of a string using the
length()
orsize()
function.std::string str10 = "Length"; size_t len = str10.length(); // len is 6 size_t size = str10.size(); // size is also 6
Understanding these basic operations is essential for effectively manipulating and comparing strings in C++.
3. Using Relational Operators for String Comparison
C++ allows you to use relational operators to compare std::string
objects directly. These operators provide a simple and intuitive way to check for equality, inequality, and lexicographical order.
3.1. Relational Operators Overview
The following relational operators can be used to compare strings:
==
(Equal to): Checks if two strings are equal.!=
(Not equal to): Checks if two strings are not equal.>
(Greater than): Checks if the first string is lexicographically greater than the second.<
(Less than): Checks if the first string is lexicographically less than the second.>=
(Greater than or equal to): Checks if the first string is lexicographically greater than or equal to the second.<=
(Less than or equal to): Checks if the first string is lexicographically less than or equal to the second.
3.2. Equality and Inequality (== and !=)
The ==
operator compares two strings for equality. It returns true
if the strings are identical and false
otherwise. The !=
operator does the opposite, returning true
if the strings are different and false
if they are the same.
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello";
std::string str2 = "Hello";
std::string str3 = "World";
if (str1 == str2) {
std::cout << "str1 and str2 are equal" << std::endl; // Output: str1 and str2 are equal
} else {
std::cout << "str1 and str2 are not equal" << std::endl;
}
if (str1 != str3) {
std::cout << "str1 and str3 are not equal" << std::endl; // Output: str1 and str3 are not equal
} else {
std::cout << "str1 and str3 are equal" << std::endl;
}
return 0;
}
3.3. Lexicographical Comparison (>, <, >=, <=)
The >
, <
, >=
, and <=
operators compare strings lexicographically, which means they compare the strings character by character based on their ASCII values.
- If the first differing character in
str1
has a higher ASCII value than the corresponding character instr2
, thenstr1 > str2
istrue
. - If the first differing character in
str1
has a lower ASCII value than the corresponding character instr2
, thenstr1 < str2
istrue
. - If the strings are identical, the comparison continues based on the length of the strings. Shorter strings are considered less than longer strings.
#include <iostream>
#include <string>
int main() {
std::string str1 = "apple";
std::string str2 = "banana";
std::string str3 = "apple";
std::string str4 = "app";
if (str1 < str2) {
std::cout << "str1 is less than str2" << std::endl; // Output: str1 is less than str2
} else {
std::cout << "str1 is not less than str2" << std::endl;
}
if (str1 > str4) {
std::cout << "str1 is greater than str4" << std::endl; // Output: str1 is greater than str4
} else {
std::cout << "str1 is not greater than str4" << std::endl;
}
if (str1 >= str3) {
std::cout << "str1 is greater than or equal to str3" << std::endl; // Output: str1 is greater than or equal to str3
} else {
std::cout << "str1 is not greater than or equal to str3" << std::endl;
}
return 0;
}
3.4. Practical Examples with Relational Operators
3.4.1. Sorting Strings
Relational operators can be used to sort an array or vector of strings in lexicographical order.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int main() {
std::vector<std::string> fruits = {"banana", "apple", "orange", "grape"};
std::sort(fruits.begin(), fruits.end());
std::cout << "Sorted fruits:" << std::endl;
for (const auto& fruit : fruits) {
std::cout << fruit << std::endl;
}
// Output:
// Sorted fruits:
// apple
// banana
// grape
// orange
return 0;
}
3.4.2. Validating User Input
Relational operators can be used to validate user input against predefined values.
#include <iostream>
#include <string>
int main() {
std::string userInput;
std::cout << "Enter 'yes' or 'no': ";
std::cin >> userInput;
if (userInput == "yes") {
std::cout << "You entered yes" << std::endl;
} else if (userInput == "no") {
std::cout << "You entered no" << std::endl;
} else {
std::cout << "Invalid input" << std::endl;
}
return 0;
}
3.5. Advantages and Limitations of Relational Operators
Advantages:
- Simplicity: Relational operators are easy to use and understand.
- Readability: The code is concise and readable.
- Efficiency: For simple comparisons, relational operators are often very efficient.
Limitations:
- Case Sensitivity: Relational operators perform case-sensitive comparisons.
- Limited Flexibility: They do not offer options for substring comparisons or custom comparison criteria.
- No Detailed Comparison Information: They only provide a boolean result, not detailed information about the comparison.
4. Using std::string::compare()
for Advanced String Comparison
The std::string::compare()
function offers more advanced and flexible string comparison options compared to relational operators. It provides detailed information about the comparison result and allows for substring comparisons.
4.1. compare()
Function Overview
The compare()
function is a member function of the std::string
class. It compares a string or a portion of a string with another string or substring. The function returns an integer value indicating the relationship between the strings:
- 0: If the strings are equal.
- Positive value: If the first string is greater than the second string.
- Negative value: If the first string is less than the second string.
4.2. Syntax and Parameters
The compare()
function has several overloaded versions with different parameters:
-
int compare(const string& str) const;
- Compares the string with another string
str
.
std::string str1 = "Hello"; std::string str2 = "World"; int result = str1.compare(str2);
- Compares the string with another string
-
int compare(size_t pos, size_t len, const string& str) const;
- Compares a substring of the string (starting at position
pos
with lengthlen
) with another stringstr
.
std::string str1 = "Hello World"; std::string str2 = "World"; int result = str1.compare(6, 5, str2);
- Compares a substring of the string (starting at position
-
int compare(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) const;
- Compares a substring of the string (starting at position
pos
with lengthlen
) with a substring of another stringstr
(starting at positionsubpos
with lengthsublen
).
std::string str1 = "Hello World"; std::string str2 = "Another World"; int result = str1.compare(6, 5, str2, 8, 5);
- Compares a substring of the string (starting at position
-
int compare(const char* s) const;
- Compares the string with a C-style character array
s
.
std::string str1 = "Hello"; const char* charArray = "World"; int result = str1.compare(charArray);
- Compares the string with a C-style character array
-
int compare(size_t pos, size_t len, const char* s) const;
- Compares a substring of the string (starting at position
pos
with lengthlen
) with a C-style character arrays
.
std::string str1 = "Hello World"; const char* charArray = "World"; int result = str1.compare(6, 5, charArray);
- Compares a substring of the string (starting at position
-
int compare(size_t pos, size_t len, const char* s, size_t n) const;
- Compares a substring of the string (starting at position
pos
with lengthlen
) with the firstn
characters of a C-style character arrays
.
std::string str1 = "Hello World"; const char* charArray = "Another World"; int result = str1.compare(6, 5, charArray, 5);
- Compares a substring of the string (starting at position
4.3. Examples of Using compare()
4.3.1. Comparing Two Strings
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello";
std::string str2 = "World";
std::string str3 = "Hello";
int result1 = str1.compare(str2);
int result2 = str1.compare(str3);
if (result1 == 0) {
std::cout << "str1 and str2 are equal" << std::endl;
} else if (result1 < 0) {
std::cout << "str1 is less than str2" << std::endl; // Output: str1 is less than str2
} else {
std::cout << "str1 is greater than str2" << std::endl;
}
if (result2 == 0) {
std::cout << "str1 and str3 are equal" << std::endl; // Output: str1 and str3 are equal
} else if (result2 < 0) {
std::cout << "str1 is less than str3" << std::endl;
} else {
std::cout << "str1 is greater than str3" << std::endl;
}
return 0;
}
4.3.2. Comparing with C-style Character Arrays
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello";
const char* charArray = "World";
int result = str1.compare(charArray);
if (result == 0) {
std::cout << "str1 and charArray are equal" << std::endl;
} else if (result < 0) {
std::cout << "str1 is less than charArray" << std::endl; // Output: str1 is less than charArray
} else {
std::cout << "str1 is greater than charArray" << std::endl;
}
return 0;
}
5. Comparing Substrings Using compare()
One of the key advantages of the compare()
function is its ability to compare substrings. This allows you to focus on specific parts of strings, making it useful for parsing and data extraction.
5.1. Comparing Substrings of Two std::string
Objects
You can compare substrings of two std::string
objects using the following compare()
overload:
int compare(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) const;
This function compares a substring of the calling string (starting at position pos
with length len
) with a substring of the string str
(starting at position subpos
with length sublen
).
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello World";
std::string str2 = "Another World";
int result = str1.compare(6, 5, str2, 8, 5); // Compare "World" from str1 and str2
if (result == 0) {
std::cout << "Substrings are equal" << std::endl; // Output: Substrings are equal
} else if (result < 0) {
std::cout << "Substring of str1 is less than substring of str2" << std::endl;
} else {
std::cout << "Substring of str1 is greater than substring of str2" << std::endl;
}
return 0;
}
5.2. Comparing Substrings with C-style Character Arrays
You can also compare substrings of a std::string
object with C-style character arrays using the following compare()
overloads:
int compare(size_t pos, size_t len, const char* s) const;
int compare(size_t pos, size_t len, const char* s, size_t n) const;
The first function compares a substring of the calling string (starting at position pos
with length len
) with the C-style character array s
. The second function compares a substring of the calling string with the first n
characters of the C-style character array s
.
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello World";
const char* charArray = "World";
int result1 = str1.compare(6, 5, charArray); // Compare "World" from str1 with charArray
int result2 = str1.compare(0, 5, charArray, 5); // Compare "Hello" from str1 with first 5 chars of charArray
if (result1 == 0) {
std::cout << "Substring and charArray are equal" << std::endl; // Output: Substring and charArray are equal
} else {
std::cout << "Substring and charArray are not equal" << std::endl;
}
if (result2 == 0) {
std::cout << "Substring and first 5 chars of charArray are equal" << std::endl;
} else {
std::cout << "Substring and first 5 chars of charArray are not equal" << std::endl; // Output: Substring and first 5 chars of charArray are not equal
}
return 0;
}
5.3. Practical Examples of Substring Comparison
5.3.1. Parsing Data from a String
Substring comparison can be used to parse data from a string by extracting and comparing specific parts of the string.
#include <iostream>
#include <string>
int main() {
std::string data = "Name: John Doe, Age: 30";
// Extract name and age
size_t namePos = data.find("Name: ");
size_t agePos = data.find(", Age: ");
if (namePos != std::string::npos && agePos != std::string::npos) {
size_t nameStart = namePos + 6;
size_t nameLength = agePos - nameStart;
std::string name = data.substr(nameStart, nameLength);
std::string ageStr = data.substr(agePos + 7);
std::cout << "Name: " << name << std::endl; // Output: Name: John Doe
std::cout << "Age: " << ageStr << std::endl; // Output: Age: 30
// Validate the extracted data
if (name.compare("John Doe") == 0) {
std::cout << "Name is valid" << std::endl; // Output: Name is valid
} else {
std::cout << "Name is invalid" << std::endl;
}
}
return 0;
}
5.3.2. Checking File Extensions
Substring comparison can be used to check the file extension of a filename.
#include <iostream>
#include <string>
int main() {
std::string filename = "document.pdf";
std::string extension = "pdf";
// Extract the file extension
size_t dotPos = filename.find_last_of(".");
if (dotPos != std::string::npos) {
std::string fileExtension = filename.substr(dotPos + 1);
// Compare the extracted extension with the expected extension
if (fileExtension.compare(extension) == 0) {
std::cout << "File has the correct extension" << std::endl; // Output: File has the correct extension
} else {
std::cout << "File has an incorrect extension" << std::endl;
}
}
return 0;
}
6. Case Sensitivity in String Comparison
By default, string comparison in C++ is case-sensitive. This means that “Hello” and “hello” are considered different strings. However, you can perform case-insensitive comparisons using various techniques.
6.1. Case-Sensitive Comparison
As demonstrated in the previous sections, relational operators and the compare()
function perform case-sensitive comparisons by default.
#include <iostream>
#include <string>
int main() {
std::string str1 = "Hello";
std::string str2 = "hello";
if (str1 == str2) {
std::cout << "Strings are equal" << std::endl;
} else {
std::cout << "Strings are not equal" << std::endl; // Output: Strings are not equal
}
return 0;
}
6.2. Converting Strings to Lowercase or Uppercase
One common approach to perform case-insensitive comparisons is to convert both strings to either lowercase or uppercase before comparing them. You can use the std::transform
function along with std::tolower
or std::toupper
to achieve this.
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
std::string toLowercase(const std::string& str) {
std::string result = str;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
int main() {
std::string str1 = "Hello";
std::string str2 = "hello";
std::string lowerStr1 = toLowercase(str1);
std::string lowerStr2 = toLowercase(str2);
if (lowerStr1 == lowerStr2) {
std::cout << "Strings are equal (case-insensitive)" << std::endl; // Output: Strings are equal (case-insensitive)
} else {
std::cout << "Strings are not equal (case-insensitive)" << std::endl;
}
return 0;
}
6.3. Using Custom Comparison Functions
Another approach is to use a custom comparison function that ignores case. You can use the std::equal
function with a custom predicate to compare the strings character by character, ignoring case.
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
bool caseInsensitiveCompare(char c1, char c2) {
return std::tolower(c1) == std::tolower(c2);
}
int main() {
std::string str1 = "Hello";
std::string str2 = "hello";
bool isEqual = std::equal(str1.begin(), str1.end(), str2.begin(), caseInsensitiveCompare);
if (isEqual) {
std::cout << "Strings are equal (case-insensitive)" << std::endl; // Output: Strings are equal (case-insensitive)
} else {
std::cout << "Strings are not equal (case-insensitive)" << std::endl;
}
return 0;
}
6.4. Using Third-Party Libraries
Some third-party libraries provide built-in functions for case-insensitive string comparison. For example, the Boost library offers the boost::algorithm::iequals
function.
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
int main() {
std::string str1 = "Hello";
std::string str2 = "hello";
if (boost::algorithm::iequals(str1, str2)) {
std::cout << "Strings are equal (case-insensitive)" << std::endl; // Output: Strings are equal (case-insensitive)
} else {
std::cout << "Strings are not equal (case-insensitive)" << std::endl;
}
return 0;
}
6.5. Performance Considerations for Case-Insensitive Comparison
- Converting strings to lowercase or uppercase can be efficient if you need to perform multiple comparisons on the same strings. However, it requires allocating new memory for the converted strings.
- Using a custom comparison function avoids memory allocation but may be slightly slower for single comparisons.
- Third-party libraries often provide optimized implementations for case-insensitive comparison, which can be the most efficient option.
Choose the method that best suits your needs based on the frequency of comparisons and the size of the strings.
7. Performance Considerations in String Comparison
The performance of string comparison can be critical in performance-sensitive applications. Understanding the factors that affect performance and choosing the right comparison method can significantly improve the efficiency of your code.
7.1. Factors Affecting String Comparison Performance
- String Length: Longer strings require more time to compare, as each character needs to be examined.
- Comparison Method: Different comparison methods have different performance characteristics. Relational operators are generally faster for simple equality checks, while
compare()
provides more flexibility but may be slower. - Case Sensitivity: Case-insensitive comparisons often require additional processing, such as converting strings to lowercase or uppercase, which can impact performance.
- Hardware: The speed of the processor and the amount of available memory can also affect string comparison performance.
7.2. Comparing Performance of Relational Operators and compare()
For simple equality and inequality checks, relational operators are generally faster than the compare()
function. This is because relational operators can stop comparing the strings as soon as a difference is found, while compare()
always compares the entire string.
However, for more complex comparisons, such as substring comparisons or comparisons that require detailed information about the relationship between the strings, compare()
can be more efficient.
7.3. Optimizing String Comparison Performance
Here are some tips for optimizing string comparison performance:
- Use Relational Operators for Simple Equality Checks: For simple equality and inequality checks, use relational operators instead of
compare()
. - Minimize String Length: Avoid comparing unnecessarily long strings. If you only need to compare a portion of the string, use substring comparison.
- Use Case-Sensitive Comparison When Possible: Case-insensitive comparisons are slower than case-sensitive comparisons. Use case-sensitive comparisons whenever possible.
- Use Efficient Case-Insensitive Comparison Methods: If you need to perform case-insensitive comparisons, choose the most efficient method based on the frequency of comparisons and the size of the strings.
- Profile Your Code: Use a profiler to identify performance bottlenecks in your code. This can help you determine whether string comparison is a significant factor in your application’s performance.
- Consider Using Hash Codes: If you need to compare strings frequently, consider pre-calculating hash codes for the strings. Comparing hash codes is much faster than comparing the strings themselves. However, you need to handle hash collisions.
7.4. Benchmarking String Comparison Performance
To accurately assess the performance of different string comparison methods, you can use benchmarking techniques. Here’s an example of how to benchmark the performance of relational operators and compare()
:
#include <iostream>
#include <string>
#include <chrono>
#include <vector>
int main() {
// Create a large vector of strings
std::vector<std::string> strings;
for (int i = 0; i < 1000; ++i) {
strings.push_back("String " + std::to_string(i));
}
// Benchmark relational operators
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 1000000; ++i) {
std::string str1 = strings[i % strings.size()];
std::string str2 = strings[(i + 1) % strings.size()];
bool isEqual = (str1 == str2);
}
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "Relational operators: " << duration.count() << " microseconds" << std::endl;
// Benchmark compare() function
start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 1000000; ++i) {
std::string str1 = strings[i % strings.size()];
std::string str2 = strings[(i + 1) % strings.size()];
int result = str1.compare(str2);
bool isEqual = (result == 0);
}
end = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "compare() function: " << duration.count() << " microseconds" << std::endl;
return 0;
}
This code benchmarks the performance of relational operators and the compare()
function by performing a large number of comparisons and measuring the execution time. By running this benchmark on your own system, you can get a sense of the relative performance of the different comparison methods.
8. Best Practices for String Comparison in C++
Following best practices when comparing strings in C++ can help you write cleaner, more efficient, and more maintainable code.
8.1. Use the Right Tool for the Job
Choose the appropriate string comparison method based on your specific needs.
- Use relational operators (
==
,!=
,>
,<
,>=
,<=
) for simple equality, inequality, and lexicographical comparisons. - Use
std::string::compare()
for more complex comparisons, such as substring comparisons or comparisons that require detailed information about the relationship between the strings.
8.2. Be Aware of Case Sensitivity
String comparison in C++ is case-sensitive by default. If you need to perform case-insensitive comparisons, use one of the techniques described in the “Case Sensitivity in String Comparison” section.
8.3. Minimize String Length
Avoid comparing unnecessarily long strings. If you only need to compare a portion of the string, use substring comparison.
8.4. Handle Null or Empty Strings
Be careful when comparing strings that might be null or empty. Null strings can cause crashes or unexpected behavior. Empty strings can lead to incorrect comparison results.
8.5. Use Clear and Descriptive Variable Names
Use clear and descriptive variable names to make your code easier to understand. For example, use firstName
and lastName
instead of str1
and str2
.
8.6. Comment Your Code
Add comments to your code to explain what it does and why. This will make your code easier to understand and maintain.
8.7. Test Your Code
Thoroughly test your code to ensure that it works correctly in all cases. This includes testing with different string lengths, different character sets, and different case sensitivities.
8.8. Follow Consistent Coding Conventions
Follow consistent coding conventions to make your code more readable and maintainable. This includes using consistent indentation