On this page
strmisc
This module contains various string utility routines that are uncommonly used in comparison to strutils.
Imports
Procs
-
proc expandTabs(s: string; tabSize: int = 8): string {...}{.noSideEffect, raises: [], tags: [].}
-
Expand tab characters in
s
replacing them by spaces.The amount of inserted spaces for each tab character is the difference between the current column number and the next tab position. Tab positions occur every
tabSize
characters. The column number starts at 0 and is increased with every single character and inserted space, except for newline, which resets the column number back to 0.Example:
Source EditdoAssert expandTabs("\t", 4) == " " doAssert expandTabs("\tfoo\t", 4) == " foo " doAssert expandTabs("\tfoo\tbar", 4) == " foo bar" doAssert expandTabs("\tfoo\tbar\t", 4) == " foo bar " doAssert expandTabs("ab\tcd\n\txy\t", 3) == "ab cd\n xy "
-
proc partition(s: string; sep: string; right: bool = false): (string, string, string) {...}{.noSideEffect, raises: [], tags: [].}
-
Split the string at the first or last occurrence of
sep
into a 3-tupleReturns a 3 string tuple of (beforeSep,
sep
, afterSep) or (s
, "", "") ifsep
is not found andright
is false or ("", "",s
) ifsep
is not found andright
is trueExample:
Source EditdoAssert partition("foo:bar", ":") == ("foo", ":", "bar") doAssert partition("foobarbar", "bar") == ("foo", "bar", "bar") doAssert partition("foobarbar", "bank") == ("foobarbar", "", "") doAssert partition("foobarbar", "foo") == ("", "foo", "barbar") doAssert partition("foofoobar", "bar") == ("foofoo", "bar", "")
-
proc rpartition(s: string; sep: string): (string, string, string) {...}{. noSideEffect, raises: [], tags: [].}
-
Split the string at the last occurrence of
sep
into a 3-tupleReturns a 3 string tuple of (beforeSep,
sep
, afterSep) or ("", "",s
) ifsep
is not foundExample:
Source EditdoAssert rpartition("foo:bar", ":") == ("foo", ":", "bar") doAssert rpartition("foobarbar", "bar") == ("foobar", "bar", "") doAssert rpartition("foobarbar", "bank") == ("", "", "foobarbar") doAssert rpartition("foobarbar", "foo") == ("", "foo", "barbar") doAssert rpartition("foofoobar", "bar") == ("foofoo", "bar", "")
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/strmisc.html