Textual data explained | Introducing characters, strings, and encodings for programming beginners
text
Understanding Textual Data in Computer Programs
Textual data serves as one of the two fundamental types of data in every computer program. We utilize it to represent the external world. So, how do we actually work with it? Let's find out.
Our journey starts by analyzing text at its most basic unitβcharacters. Whether it's a letter, a number, or a symbol, each character is crucial for creating textual data.
Characters: The Building Blocks
In programming, every symbol is known as a character. Not just letters, but numbers, punctuation marks, and other special symbols all count as characters. In essence, a character is the smallest textual unit in programming.
Strings: More Than Just Characters
Characters alone aren't enough for most tasks. We string them together to form sequences of characters, commonly known as strings. For example, the text Deeplizard consists of 10
characters strung together.
// JavaScript example
let string = "DEEPLIZARD";
let length = string.length; // Outputs 10
Indexing in Strings
Within a string, each character can be accessed by its index. Indexing starts from 0
, allowing us to easily reference each character in a string. For instance, in the string DEEPLIZARD the character at index 6
is Z.
// JavaScript example
let character = string.charAt(6); // Outputs 'Z'
The Screen vs Under the Hood
What we see on our screen is a representation made up of pixels. However, computers understand each character as a specific number, thanks to character encoding.
Each character corresponds to a unique number in the computer's memory, similar to Morse code or Braille in the physical world. While we interact with textual data as characters, the computer interacts with their numerical representations.
quiz
resources
updates
Committed by on