Logo

Programming-Idioms

  • Python
  • Js

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
Character indices start at 0 unless specified otherwise.
Make sure that multibyte characters are properly handled.

let t = s.substring(i, j);
let t = s.slice(i, j);
t = s[slice(i, j)]

Python 3
t = s[i:j]

Slicing works on strings.
T : String := S (I .. J - 1);

In Ada, strings use 1-based indexing

In Ada, J is included by default when slicing

New implementation...