Introduction to
String
Md Zahim Hassan
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 1
Objectives
• To know about string
• To know about string operations
• To know about pattern matching algorithm in string
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 2
String
• A finite sequence S of zero or more characters is called string.
• The number of characters in a string is called it’s length.
• The string with zero characters is called the empty string or null string.
• A string is a null-terminated character array. This means that after the last
character, a null character ('\0') is stored to signify the end of the character
array.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 3
String vs Character
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 4
Storing String
1. Fixed Length Structure:
• Each line of entry is viewed as record and all records have the same length.
• Think of it like a row of identical boxes—each box can hold a certain number of items, no
more, no less in terms of allocated space.
• If the string is shorter than the box size, the extra space is usually padded (often with null
characters or spaces). If it’s longer, it gets cut off.
2. Variable Length Structure:
• Strings can vary in length, but there’s still an upper limit to how long they can be.
• It’s like having stretchy bags with a maximum capacity—each bag can hold a different
amount, but none can exceed the biggest size allowed.
• The actual length of the string is tracked, so no padding is needed for shorter strings,
unlike fixed length.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 5
Storing String
1. Linked Structure:
• Linked structures are like a chain of building blocks.
• Each block (or node) holds a piece of the string—usually one character—and points to
the next block.
• There’s no fixed size limit; the string can grow as long as it keep adding blocks (assuming
memory is available).
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 6
String Operations
• Finding Length of String:
• The number of characters in a string constitutes the length of the string.
• For example, LENGTH("C PROGRAMMING IS FUN") will return 20. Note that even blank
spaces are counted as characters in the string.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 7
String Operations
• String Concatenation:
• Appending one string to another string involves copying the contents of the source string
at the end of the destination string. For example, if S1 and S2 are two strings, then
appending S1 to S2 means we have to add the contents of S1 to S2.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 8
String Operations
• Comparing Two Strings:
• To compare the two
strings, each and every
character is compared
from both the strings. If
all the characters are the
same, then the two
strings are said to be
equal.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 9
String Operations
• Extracting Substring from a String:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 10
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 11
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 12
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 13
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 14
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 15
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 16
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 17
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 18
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 19
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 20
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 21
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 22
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 23
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 24
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 25
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 26
String Operations
• Pattern Matching:
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 27
String Operations
• Pattern Matching:
And It Goes So on.
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 28
Extra Resources
• https://lobb.nz/stringmatchvisualiser/stringmatching.html#
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 29
Thank You
08/07/2025 Md Zahim Hassan, Lecturer, CSE, BAUST 30