On this page
std/strmisc
Source EditThis module contains various string utility routines that are uncommonly used in comparison to the ones in strutils.
Imports
Procs
-
func expandTabs(s: string; tabSize: int = 8): string {....raises: [], tags: [], forbids: [].} -
Expands 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
tabSizecharacters. 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("a\tb\n\txy\t", 3) == "a b\n xy " -
func partition(s: string; sep: string; right: bool = false): (string, string, string) {....raises: [], tags: [], forbids: [].} -
Splits the string at the first (if
rightis false) or last (ifrightis true) occurrence ofsepinto a 3-tuple.Returns a 3-tuple of strings,
(beforeSep, sep, afterSep)or(s, "", "")ifsepis not found andrightis false or("", "", s)ifsepis not found andrightis true.See also:
Example:
Source EditdoAssert partition("foo:bar:baz", ":") == ("foo", ":", "bar:baz") doAssert partition("foo:bar:baz", ":", right = true) == ("foo:bar", ":", "baz") doAssert partition("foobar", ":") == ("foobar", "", "") doAssert partition("foobar", ":", right = true) == ("", "", "foobar") -
func rpartition(s: string; sep: string): (string, string, string) {....raises: [], tags: [], forbids: [].} -
Splits the string at the last occurrence of
sepinto a 3-tuple.Returns a 3-tuple of strings,
(beforeSep, sep, afterSep)or("", "", s)ifsepis not found. This is the same aspartition(s, sep, right = true).See also:
Example:
Source EditdoAssert rpartition("foo:bar:baz", ":") == ("foo:bar", ":", "baz") doAssert rpartition("foobar", ":") == ("", "", "foobar")
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/strmisc.html