๐ŸŒ‡DSA
โ† Back
AlgorithmBeginner
๐Ÿงต

String Manipulation

Transform and analyze text

โฑ๏ธ 6โ€“10 hours๐Ÿงฉ 10 LeetCode
๐Ÿ”’ Login to unlock solutions and track progress. Login

What is it?

A string is just text โ€” a sequence of characters. String manipulation is what you do when you want to transform, inspect, or extract parts of that text.

Think of it like editing a word document: lower-case everything, find a word, swap it for another, or read it backwards.

Common Techniques

  • Two pointers โ€” check palindromes or reverse in-place
  • Frequency map โ€” detect anagrams, count characters
  • Stack โ€” validate bracket pairs, decode compressed strings
  • Sliding window โ€” find the longest substring without repeats
  • HashMap โ€” group anagrams together

Real-World Examples

Password strength check
Autocorrect & spellcheck
CSV / JSON text parsing
URL slug generator
Find & Replace in editor
Plagiarism detection

Code Example

What this code shows

On 'Hello, World!': lower-case converts every letter to its small form. includes() checks whether the substring 'World' exists inside. Reversing the characters gives the string read backwards.

const s = "Hello, World!";

// convert every character to lower-case
console.log(s.toLowerCase()); // "hello, world!"

// check if a substring exists anywhere inside
console.log(s.includes("World")); // true

// spread into chars, reverse the array, join back to string
console.log([...s].reverse().join("")); // "!dlroW ,olleH"

Expected Output

hello, world!
true
!dlroW ,olleH

LeetCode Practice