ForHosting KIT · Text & AI

Get nth word

Pick the word at any position: in alpha bravo charlie delta echo, word 3 is charlie, out of 5 words. Handy for pulling a fixed column from log lines or setting reading questions. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
alpha bravo charlie delta echo
N
3
You get
Word
charlie
Word count
5
Position
3
Words
alpha, bravo, charlie, delta, echo

Getting the word at a chosen position is a small but constant need when you parse structured lines, log columns, shell-style space-separated fields, quiz prompts, and quick data pulls from free-text exports. This tool takes the plain text you provide, splits it into words on Unicode whitespace, and returns the token at the 1-based index you choose, together with the full token list and the total word count so you can validate the pull in one response.

How the nth word is chosen from your text

Tokenization is deliberately simple and fully deterministic so results match what people expect from status bars, shell field splitters, and everyday online counters. The engine trims leading and trailing whitespace, then splits the remaining string on one or more Unicode whitespace characters—spaces, tabs, newlines, and other separators all collapse into a single boundary between tokens.

Each resulting non-empty run is one word, including any punctuation that is attached to the letters or digits of that run, so a token such as hello, or well-known stays whole rather than being further subdivided by commas or hyphens. The position parameter n is 1-based: the first word is position 1, the second is 2, and so on up to the total number of words after the split.

Because the path is pure parse arithmetic over strings—no language models, no dictionaries, no locale tables—latency stays sub-millisecond for typical form sizes and the published cost model is analytic rather than token-based.

Where nth-word extraction shows up in real work

Support and operations teams skim multi-field log lines where severity, service name, and host appear in fixed positions and want a one-click way to grab the host without writing a throwaway script. Teachers and quiz authors build prompts that refer to the second or fifth word of a sentence so students practice ordered reading, and they need the same answer key the student sees in the browser.

Localization and content QA pipelines sometimes assert that a template line still starts with a known keyword after substitution, which is exactly an n equals one check on the rendered string. If you later need full word counts, unique-word lists, reverse word order, frequency tables, or keyword density analysis, treat those as separate search intents and landings rather than overloading this get-nth-word page—the intent here is specifically “give me the word at position n,” not “describe the whole document.”

Pull a fixed column from space-separated lines

Extract the k-th field from log lines, shell exports, or free-text rows without a full CSV parser when positions are stable.

Quiz and reading prompts by word position

Build answer keys and classroom checks that ask for the second, third, or last referenced word of a fixed stem.

Template and keyword position QA

Assert that a rendered template still starts with a known token or keeps a required word at a given index after substitution.

How are words defined?

Words are non-empty runs of non-whitespace characters. Multiple spaces, tabs, and newlines collapse into one separator. Punctuation attached to a token stays with that token.

What happens if the text is empty?

Provide a non-empty string; blank boxes are treated as client errors and are not charged.

What does it cost?

The browser tool is free and runs locally.

What happens if I ask for a position past the last word?

You get a clear message instead of an empty answer, and it tells you how many words were actually found. That makes it easy to spot a miscounted column.

Do line breaks and tabs separate words?

Yes. Spaces, tabs and line breaks all act as one boundary, so a paragraph spread over several lines is read as one continuous run of words.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/str/nth-word

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/str/nth-word \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"alpha bravo charlie delta echo","n":3}'
{
  "text": "alpha bravo charlie delta echo",
  "n": 3
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "str.nth_word",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Empty input, missing positions, and out-of-range indexes fail with a clear invalid_input error instead of inventing a silent empty string, which protects scripts that forgot to bind a field or miscounted columns.

How the nth word is chosen from your text

Requesting a position less than one, a non-integer, or a number greater than the word count raises invalid_input with a message that states how many words were actually found, which makes debugging column offsets in batch jobs straightforward. Extremely long payloads above the documented character cap are rejected before the split so a single request cannot monopolize Worker memory.

What you send and what you get back

Send two required fields: text, a non-empty string to tokenize, and n, a positive integer for the 1-based word position. Numbers and booleans on the text field are coerced to their decimal or true/false text forms; objects, arrays, NaN, and Infinity are rejected. Classic checks include pulling the third token from a five-word NATO-style list, taking the first word of a multi-line paragraph where newlines act as ordinary separators, and confirming that a trailing period stays attached to its token when you ask for that position. Wire the free browser form for paste-and-check work on log lines and quiz stems, then call the identical contract from scripts when you need the k-th field from thousands of space-separated rows. Aliases such as input, value, data, s, string, content, body, and phrase are accepted for the text field when wiring older clients, and n also accepts index, position, pos, i, nth, and word_index for convenience in shells and spreadsheets. On success the response echoes the original text, returns n and position (the same 1-based index), the extracted word, word_count for the full token list, the complete words array in order, and operation set to nth_word. Empty text, whitespace-only text after trim, missing n, non-integer n, n less than one, and n greater than word_count all fail validation before any charge applies. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.

Where nth-word extraction shows up in real work

Data analysts and engineers often need a single column from a free-text export that was never fully parsed into CSV: the third space-separated field might be a status code, a username, or a product SKU, and pulling it with a stable 1-based index is faster than opening a spreadsheet for every file. Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.

Is the position 1-based or 0-based?

Positions are 1-based: n=1 is the first word, n=2 the second, and so on. Values less than 1 or greater than the word count raise invalid_input.

What if I request a position past the end of the text?

The request fails with invalid_input and a message that includes how many words were found, so you can correct the index or the source line.

Read the full KIT documentation →