Skip to main content

Add Prefix and Suffix to Every Line Add a prefix and/or suffix to each line of text.

Prefix/Suffix Lines illustration
📝

Prefix/Suffix Lines

Add a prefix and/or suffix to each line of text.

1

Paste Text

Paste the text to modify.

2

Set Prefix/Suffix

Enter text to add before and/or after each line.

3

Copy Result

Copy the text with prefixes and suffixes applied.

Loading tool...

What Is Prefix/Suffix Lines?

A Prefix/Suffix Lines tool is a utility that modifies text by adding custom strings to the beginning and end of each line, allowing users to prepend and append text in bulk. Developers and data analysts use it to format code, add comment markers, or prepare text for specific formats like CSV or JSON. One specific problem it solves is the need to add prefixes or suffixes to multiple lines of code simultaneously, such as when wrapping lines in HTML tags or creating list markup.

The tool's users can set a prefix, a suffix, or both, and an optional toggle allows them to skip empty lines, keeping them clean and free of unnecessary characters. What makes this implementation different is its ability to handle empty lines through the `skipEmpty` state variable, which determines whether to apply the prefix and suffix to all lines or only non-empty ones.

It also features input fields for setting custom prefixes and suffixes, allowing users to add text to the beginning and end of lines with precision. For example, a user can add a prefix to each line of code to denote it as a comment, or append a suffix to indicate the data type. By using this tool, users can efficiently bulk add prefix suffix online, saving them from manual editing and potential errors when working with large datasets or complex codebases.

Why Use Prefix/Suffix Lines?

  • Add consistent text to the start or end of every line
  • Option to skip empty lines
  • Combine prefix and suffix in one operation
  • Useful for code formatting and list creation

Common Use Cases

Code Commenting

Add comment markers (// or #) to the beginning of each line.

List Formatting

Insert bullet points, numbers, or markers before each line.

HTML Wrapping

Wrap each line in HTML tags like <li> and </li>.

SQL Formatting

Prepare values for SQL IN clauses by wrapping them in quotes and commas.

Technical Guide

The tool's core functionality relies on React's useState hook to store the prefix, suffix, and skipEmpty state variables. When the user inputs a prefix or suffix, the corresponding state variable is updated using the setPrefix or setSuffix function. The skipEmpty state is toggled using the setSkipEmpty function when the checkbox is clicked. Under the hood, the onProcess callback function uses the split method to divide the input string into an array of lines separated by newline characters (\n). It then maps over this array, applying the prefix and suffix to each line using simple string concatenation.

The tool's ability to handle empty lines is facilitated by the skipEmpty state variable, which determines whether to apply the prefix and suffix to all lines or only non-empty ones. If skipEmpty is true, the trim method is used to remove whitespace from each line, and if the resulting string is empty, the line is returned unchanged. This approach ensures that empty lines are preserved in their original form when the skip-empty-lines option is enabled. The processed lines are then joined back together using the join method with a newline character (\n) as the separator.

The TextToolLayout component from the @/components/shared directory provides a basic structure for the tool's interface, including input fields for setting custom prefixes and suffixes. These input fields use React's onChange event handler to update the corresponding state variables when the user types in a new prefix or suffix. The glass-input class is applied to these input fields to provide a consistent visual style throughout the application. By using React's useCallback hook to memoize the onProcess function, the tool ensures that it only re-renders when necessary, improving performance and reducing unnecessary computations.

Tips & Best Practices

  • 1
    Use prefix "// " to comment out every line
  • 2
    Use prefix "- " to create a Markdown list
  • 3
    Use prefix "<li>" and suffix "</li>" for HTML list items
  • 4
    Skip empty lines to keep paragraph breaks clean

Related Tools

Frequently Asked Questions

Q Can I add just a prefix or just a suffix?
Yes, leave either field empty to only add the other.
Q What does "skip empty lines" do?
When enabled, empty lines (whitespace-only) are not modified.
Q Can I use special characters in the prefix/suffix?
Yes, any text can be used including special characters, HTML tags, and Unicode.
Q Does it work with multi-line prefix/suffix?
The prefix and suffix are added as-is. Multi-character strings work but multi-line ones may produce unexpected results.
Q How is this different from Indent?
Indent adds whitespace specifically. This tool adds any custom text to both the start and end of lines.

About This Tool

Prefix/Suffix Lines is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.