1textutil::trim(n) Text and string utilities, macro processingtextutil::trim(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       textutil::trim - Procedures to trim strings
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require textutil::trim  ?0.7?
14
15       ::textutil::trim::trim string ?regexp?
16
17       ::textutil::trim::trimleft string ?regexp?
18
19       ::textutil::trim::trimright string ?regexp?
20
21       ::textutil::trim::trimPrefix string prefix
22
23       ::textutil::trim::trimEmptyHeading string
24
25______________________________________________________________________________
26

DESCRIPTION

28       The  package  textutil::trim  provides commands that trim strings using
29       arbitrary regular expressions.
30
31       The complete set of procedures is described below.
32
33       ::textutil::trim::trim string ?regexp?
34              Remove in string any leading and trailing substring according to
35              the  regular  expression  regexp  and return the result as a new
36              string.  This is done for all lines in the string, that  is  any
37              substring  between  2 newline chars, or between the beginning of
38              the string and a newline, or between a newline and  the  end  of
39              the  string,  or,  if the string contain no newline, between the
40              beginning and the end of the  string.   The  regular  expression
41              regexp defaults to "[ \\t]+".
42
43       ::textutil::trim::trimleft string ?regexp?
44              Remove  in string any leading substring according to the regular
45              expression regexp and return the result as a  new  string.  This
46              apply on any line in the string, that is any substring between 2
47              newline chars, or between the beginning of the string and a new‐
48              line, or between a newline and the end of the string, or, if the
49              string contain no newline, between the beginning and the end  of
50              the  string.   The  regular  expression  regexp  defaults  to "[
51              \\t]+".
52
53       ::textutil::trim::trimright string ?regexp?
54              Remove in string any trailing substring according to the regular
55              expression  regexp  and  return the result as a new string. This
56              apply on any line in the string, that is any substring between 2
57              newline chars, or between the beginning of the string and a new‐
58              line, or between a newline and the end of the string, or, if the
59              string  contain no newline, between the beginning and the end of
60              the string.   The  regular  expression  regexp  defaults  to  "[
61              \\t]+".
62
63       ::textutil::trim::trimPrefix string prefix
64              Removes  the prefix from the beginning of string and returns the
65              result. The string is left unchanged if it doesn't  have  prefix
66              at its beginning.
67
68       ::textutil::trim::trimEmptyHeading string
69              Looks for empty lines (including lines consisting of only white‐
70              space) at the beginning of the string and removes it. The  modi‐
71              fied string is returned as the result of the command.
72

BUGS, IDEAS, FEEDBACK

74       This  document,  and the package it describes, will undoubtedly contain
75       bugs and other problems.  Please report such in the  category  textutil
76       of  the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].  Please
77       also report any ideas for enhancements you may have for either  package
78       and/or documentation.
79
80       When proposing code changes, please provide unified diffs, i.e the out‐
81       put of diff -u.
82
83       Note further that  attachments  are  strongly  preferred  over  inlined
84       patches.  Attachments  can  be  made  by  going to the Edit form of the
85       ticket immediately after its creation, and  then  using  the  left-most
86       button in the secondary navigation bar.
87

SEE ALSO

89       regexp(n), split(n), string(n)
90

KEYWORDS

92       prefix, regular expression, string, trimming
93

CATEGORY

95       Text processing
96
97
98
99tcllib                                0.7                    textutil::trim(n)
Impressum