Add Prefix and Suffix to Text
Add prefix and suffix to each line or entire text block. Bulk text processing tool with line numbering, trimming, and instant preview.
About
Manually prepending or appending strings to hundreds of lines introduces transcription errors and costs measurable time. This tool applies a user-defined prefix (P) and suffix (S) to every line (Li) of an input text block in a single operation. It handles edge cases that naive find-and-replace misses: empty lines, trailing whitespace, inconsistent line endings (CRLF vs LF). The output is deterministic - given the same input and parameters, the result is always identical. Use it for SQL column wrapping, HTML list generation, CSV field quoting, log annotation, or bulk code commenting.
The tool assumes UTF-8 input. Lines are split on newline boundaries. An optional line-numbering mode zero-pads indices to maintain column alignment. Note: applying a prefix or suffix to an empty line still produces output unless the "Skip Empty Lines" option is active. For whole-text mode, the prefix and suffix are applied once to the entire block, not per line.
Formulas
The transformation applied to each line is a simple concatenation operation:
Where Oi is the output line at index i, P is the prefix string, Li is the original input line at index i, and S is the suffix string. When line numbering is enabled, the formula extends to:
Where pad(n, w) zero-pads the number n to width w = floor(log10(N)) + 1, N is the total line count, and D is the delimiter string (default: ". "). The skip-empty-lines filter applies a predicate before transformation: only lines where Li.trim().length > 0 are processed.
Reference Data
| Use Case | Prefix | Suffix | Example Input Line | Example Output Line |
|---|---|---|---|---|
| SQL Quoting | " | ", | john_doe | "john_doe", |
| HTML List Items | <li> | </li> | Apples | <li>Apples</li> |
| CSS Comments | /* | */ | old rule | /* old rule */ |
| Markdown Bold | ** | ** | important | **important** |
| CSV Quoting | " | " | Hello, World | "Hello, World" |
| Log Timestamps | [2024-01-15] | Server started | [2024-01-15] Server started | |
| Bullet Points | • | First item | • First item | |
| XML Tags | <item> | </item> | Widget | <item>Widget</item> |
| Line Comment (JS) | // | deprecated call | // deprecated call | |
| Shell Echo | echo " | " | Hello | echo "Hello" |
| Parentheses Wrap | ( | ) | sub-expression | (sub-expression) |
| Numbering | 01. | Chapter One | 01. Chapter One | |
| Python Print | print(" | ") | debug value | print("debug value") |
| Tab Indent | \t | nested line | \tnested line | |
| Hashtag | # | coding | #coding | |
| Email Quoting | > | Original message | > Original message | |
| Array Element (JS) | " | ", | apple | "apple", |
| LaTeX Command | \textbf{ | } | theorem | \textbf{theorem} |