Object-Oriented Programming (OOP)

4. Introduction to Data Types

4.4. String

A string is a sequence of characters, used to represent text.

Characteristics

Storage: Varies by language; typically an array of characters plus metadata (e.g., length).

Immutable in some languages (e.g., Java, Python), meaning they cannot be changed after creation.

Operations: Concatenation (+), substring extraction, length calculation, case conversion, etc.

Use Cases

Storing and manipulating text (e.g., names, messages).

User input/output.

Data parsing (e.g., JSON, CSV).

Examples

Python: s = "Hello, World!"

Java: String s = "Hello, World!";

C++: std::string s = "Hello, World!";

Notes

In C, strings are arrays of characters ending with a null terminator (\0).

Python and Java strings are immutable, requiring new strings for modifications.

C++ strings (via std::string) are mutable.