How to use the Substring Selector & Code Generator
1. Enter or paste your full string in the text box above.
2. Drag to select any portion of the text — the indices update instantly.
3. Or type a substring in the search field to locate it by index.
4. Switch between Start+End and Start+Length modes to match your language's API.
5. Copy the generated code for your language of choice.
What is it?
String indexing is zero-based in most languages: the first character is at index 0. Substring extraction differs across languages — some use start+end indices (JavaScript's substring, Python's slice, Java's substring, Go's slice), while others use start+length (PHP's substr, C#'s Substring).
The end index in Start+End mode is exclusive — str.substring(6, 11) returns characters at positions 6, 7, 8, 9, 10 — not 11.
Benefits
Transform large text files without writing a script
Sort, deduplicate, clean, number, split, or reformat thousands of lines instantly in the browser — tasks that would take a Python or bash one-liner, done in one click.
Accurate counts for any writing constraint
Word and character counts that respect real constraints: 280-character tweets, SMS length limits, database column maximums, or API payload size budgets.
Prepare text for downstream systems
Remove trailing whitespace, normalize line endings, strip unwanted characters, or reformat columns before importing into databases, spreadsheets, or data pipelines.
Bulk operations without opening a spreadsheet or IDE
Process entire documents — shuffle lines for randomised testing, repeat patterns for test fixtures, extract specific columns — without switching tools.
Frequently asked questions
Why is my end index one more than expected?
End indices in substring functions are exclusive — they mark the position after the last character. So to extract a 5-character word starting at index 6, you use end index 11 (6 + 5). This is consistent across JavaScript, Python, Java, and Go.
What if my substring appears multiple times?
Use the occurrence picker that appears under the substring input. It lists First, Second, Third... match and jumps the selection to each instance.
What is the difference between Start+End and Start+Length modes?
Start+End gives you both index markers (e.g. 6 to 11). Start+Length gives you the start index and how many characters to take (e.g. start at 6, take 5). PHP's substr() and C#'s Substring() use start+length, while Python slices and Java's substring() use start+end.
Does this work with Unicode characters?
The indices shown are JavaScript string indices (UTF-16 code units), which match Python str indices for most text. For emoji or characters outside the Basic Multilingual Plane, a single visible character may occupy 2 code units — the generated code handles this correctly in JavaScript but note that Go counts bytes, not characters.