5.8 Comparing Strings

Strings can be compared in various ways using relational operators, similar to how numbers are compared.

However, since strings consist of characters, these comparisons are performed character by character, based on each character’s ASCII (or Unicode) value.

Strings can be compared using

  • Equality and inequality: ==, !=
  • Relational operator: >, <, >=, <=
  • Case Sensitivity: String comparisons are case-sensitive, meaning 'Hello' and 'hello' are considered not equal.
  • These comparisons are done character by character from left to right, using the ASCII value of each character.