Text Truncator
Truncate text to a specified character or word limit with a customizable ellipsis.
About this tool
The Text Truncator is a simple yet powerful tool for shortening text to a specific length or word count. Whether you're crafting social media posts with character limits, preparing product descriptions for e-commerce platforms, or fitting text into constrained UI spaces, this tool ensures your content meets exact requirements without manual counting or tedious editing.
To use the Text Truncator, simply paste your text into the input field, choose whether you want to truncate by character count or word count, and set your target limit. The tool instantly shows you the truncated result, and you can customize the ellipsis (the ending punctuation) to match your needs—use the standard three dots, a single character, or leave it blank. Copy the result with one click and use it wherever needed.
This tool is especially useful for developers working with APIs that have strict input length limits, content creators managing multiple platforms with different requirements, and professionals who need consistent formatting across documents. Keep in mind that truncating mid-word by character count may result in incomplete words, so word-count mode is often a safer choice when readability matters.
Frequently Asked Questions
Code Implementation
def truncate_chars(text: str, max_chars: int, ellipsis: str = "...") -> str:
"""Truncate text to max_chars characters."""
if len(text) <= max_chars:
return text
return text[:max_chars - len(ellipsis)] + ellipsis
def truncate_words(text: str, max_words: int, ellipsis: str = "...") -> str:
"""Truncate text to max_words words."""
words = text.split()
if len(words) <= max_words:
return text
return " ".join(words[:max_words]) + ellipsis
# Examples
text = "The quick brown fox jumps over the lazy dog"
print(truncate_chars(text, 20)) # "The quick brown fo..."
print(truncate_words(text, 5)) # "The quick brown fox jumps..."
print(truncate_chars(text, 20, " …")) # "The quick brown f …"Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.