String Basic Operations Visualization & Animation

Covers core string primitives — access, concat, substring, search, and split — with their complexity tradeoffs.

## What is it? String Basic Operations covers the core operations you perform on strings: accessing characters by index, finding substrings, concatenation, splitting, replacing, and checking properties like length or emptiness. ## How it works Key operations and their typical complexity: - **Access** character at index `i` → O(1) - **Length** → O(1) in most languages - **Concatenation** `s1 + s2` → O(n+m); use `StringBuilder` for repeated concatenation - **Substring** `s[i:j]` → O(j-i) — creates a copy in most languages - **Search** (`indexOf`, `find`) → O(n*m) naive, O(n) with KMP - **Split / Replace** → O(n) ## When to use - Parsing input (CSV, JSON, commands) - Building output strings efficiently - Cleaning and normalizing text data ## Key Points - Strings are **immutable** in Java, Python, JavaScript — every "modification" creates a new string - Use `StringBuilder` (Java) or `list.join()` (Python) for O(n) concatenation in loops - Always handle edge cases: empty string, single character, unicode characters

Category: algorithms

Difficulty: beginner

Time Complexity: O(n)

Space Complexity: O(n)

String Basic Operations

beginner

Covers core string primitives — access, concat, substring, search, and split — with their complexity tradeoffs.

Input String
j
[0]
a
[1]
v
[2]
a
[3]
s
[4]
c
[5]
r
[6]
i
[7]
p
[8]
t
[9]
Select an operation and click Apply
String Operations
Returns the number of UTF-16 code units in the string. A read-only property, not a method.

Length: 10  ·  Indices: 0 – 9

str.length

"javascript".length // → 10