Truncate text
Shorten long text to a maximum length, cutting from the middle, start or end and marking the cut with an ellipsis.
Input
Result
Fill in the input and press Run.
Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.
Use it from code or an agent
curl -s https://setget.net/v1/tools/truncate-middle \
-H 'Content-Type: application/json' \
-d '{"input":{"text":"The quick brown fox jumps over the lazy dog","max_length":20}}'
import json, urllib.request
body = {'input': {'text': 'The quick brown fox jumps over the lazy dog', 'max_length': 20}}
request = urllib.request.Request("https://setget.net/v1/tools/truncate-middle", json.dumps(body).encode(),
{"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/truncate-middle", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({"input":{"text":"The quick brown fox jumps over the lazy dog","max_length":20}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
"slug": "truncate-middle",
"input": {
"text": "The quick brown fox jumps over the lazy dog",
"max_length": 20
}
}
{
"input": {
"text": "The quick brown fox jumps over the lazy dog",
"max_length": 20
}
}
Endpoint: POST /v1/tools/truncate-middle. Over MCP: run_tool with slug: "truncate-middle".
Machine-readable: input schema, Markdown. Connect an agent.
Inputs
| Name | Type | Required | What it does |
|---|---|---|---|
text |
string | yes | The text to shorten. |
max_length |
integer | no | Longest result allowed, in characters, including the marker. Default: 80. From 1 to 1000000. |
where |
string | no | Which part to cut out. "middle" keeps the start and the end. One of: start, middle, end. Default: "middle". |
marker |
string | no | Text that stands in for the removed part. Default: "\u2026". |
Examples
Input
{
"text": "The quick brown fox jumps over the lazy dog",
"max_length": 20
}Result
{
"text": "The quick … lazy dog",
"truncated": true,
"original_length": 43,
"removed": 24
}Keeping the end of a path
Input
{
"text": "/home/sam/projects/website/assets/images/logo.png",
"max_length": 26,
"where": "start",
"marker": "..."
}Result
{
"text": ".../assets/images/logo.png",
"truncated": true,
"original_length": 49,
"removed": 26
}Already short enough
Input
{
"text": "Short text",
"max_length": 20
}Result
{
"text": "Short text",
"truncated": false,
"original_length": 10,
"removed": 0
}Questions
- Is the marker counted in the length?
- Yes. The result, marker included, is never longer than max_length.
- Does it cut accented letters in half?
- No. A cut never separates a letter from its combining accents, so the result can be a character or two shorter than the limit.
Related tools
- Text chunkerSplit long text into chunks of a maximum size for search and RAG pipelines, breaking at natural boundaries.
text-chunk - Wrap and indent textHard-wrap text to a line width, add or remove indentation, and put a prefix such as "> " on every line.
wrap-indent - Token estimatorEstimate how many LLM tokens a text uses, from its characters and words. An approximation, not an exact count.
token-estimate - Apply a patchApply a unified diff to a text and get the patched result, with clear errors when a hunk does not fit.
patch-apply - Case converterConvert text between lower, UPPER, Title, Sentence, camelCase, PascalCase, snake_case, kebab-case and more.
case-convert - Escape and unescape textEscape or unescape text for HTML, URLs, JSON strings, shell commands, regular expressions and CSV fields.
escape-unescape