WolframLang: Get SubString

By Xah Lee. Date: . Last updated: .

Get Substring, by Position

StringTake[str, n]
  • First char to nth.
  • If n is negative, count from right.

StringTake

StringTake["abcde", 3]
(* abc *)

StringTake["abcde", -3]
(* cde *)
StringTake[str, {n}]

nth char.

StringTake["abcde", {3}]
(* c *)
StringTake[str, {n, m}]

nth to mth chars.

StringTake["abcde", {2,4}]
(* bcd *)
StringTake[str, list_of_range_spec]

return a list of result, for each spec.

StringTake["abcde", {2, {2}, {2,4}}]
(* {ab, b, bcd} *)
StringTake[list_of_strings, spec]

return a list of result, for each string.

StringTake[{"abcde", "123456"}, 2]
(* {"ab", "12"} *)

StringTake[{"abcde", "123456"}, {2}]
(* {"b", "2"} *)

StringTake[{"abcde", "123456"}, {2,4}]
(* {"bcd", "234"} *)
StringTake[{"abcde", "123456"}, {2, {2}, {2,4}}]

(* {{ab, b, bcd}, {12, 2, 234}} *)

Get Substring by Pattern

WolframLang String