S0-SA5-0362
What is a String (Length)?
Grade Level:
Pre-School – Class 2
All domains without exception
Definition
What is it?
In computer science, a 'string' is a sequence of characters, like letters, numbers, or symbols, put together. The 'length' of a string is simply how many characters it contains. Think of it like counting the number of beads on a string.
Simple Example
Quick Example
Imagine your name, 'Rahul'. If we write it in a computer, it's a string. To find its length, we count each letter: R, a, h, u, l. There are 5 letters. So, the length of the string 'Rahul' is 5.
Worked Example
Step-by-Step
Let's find the length of the string 'Hello India!'.
1. Identify the string: The string is 'Hello India!'.
---
2. Start counting from the first character: H is 1.
---
3. Continue counting each character, including spaces and special symbols: e is 2, l is 3, l is 4, o is 5.
---
4. Count the space after 'Hello': Space is 6.
---
5. Continue for 'India!': I is 7, n is 8, d is 9, i is 10, a is 11, ! is 12.
---
6. The total count is 12.
---
Answer: The length of the string 'Hello India!' is 12.
Why It Matters
Understanding string length is fundamental for handling text data, which is everywhere in computing. It's crucial for software developers creating apps, data scientists analyzing social media posts, and even game developers making character names fit on screen. It helps us manage information efficiently.
Common Mistakes
MISTAKE: Not counting spaces or special characters. Students sometimes only count letters. | CORRECTION: Always count *every single character* in the string, including spaces, numbers, and symbols like '!' or '@'.
MISTAKE: Starting the count from zero. Some programming languages count from zero, but for string length, we count from one. | CORRECTION: When finding the length, always start counting from 1 for the first character.
MISTAKE: Confusing the number of words with string length. | CORRECTION: String length is about individual characters, not how many words are present. 'Good Morning' has 2 words but a length of 12 (G-o-o-d- -M-o-r-n-i-n-g).
Practice Questions
Try It Yourself
QUESTION: What is the length of the string 'Cricket'? | ANSWER: 7
QUESTION: Find the length of the string 'India@123'. | ANSWER: 9
QUESTION: A student enters their school ID as 'DPS-DELHI-2024'. What is the length of this string? | ANSWER: 13
MCQ
Quick Quiz
What is the length of the string 'Chai Garam!'?
10
11
12
9
The Correct Answer Is:
B
The string 'Chai Garam!' has 11 characters. Counting each character, including the space and the '!', gives you 11.
Real World Connection
In the Real World
When you fill out an online form, like for a new mobile connection or an exam application, sometimes there's a limit on how many characters you can type for your name or address. This is because the system checks the string length of your input to ensure it fits the database. For example, a username might be limited to 15 characters.
Key Vocabulary
Key Terms
STRING: A sequence of characters like letters, numbers, or symbols | CHARACTER: A single letter, number, space, or symbol | LENGTH: The total number of characters in a string | SEQUENCE: An ordered series of items
What's Next
What to Learn Next
Now that you understand what a string is and how to find its length, you're ready to learn about 'String Manipulation'. This is where you'll discover how to change, combine, or extract parts of strings, which is super useful in programming!


