String manipulation routines
List of Global Functions
CAlnum - The 62 upper and lowercase ASCII letters and digits
CAlpha - The 52 upper and lowercase ASCII letters
CDigit - Digits: 0123456789
CGraph - Printable ASCII charcters except whitespace, 33-126
CLower - The 26 lowercase ASCII letters
CPrint - Printable ASCII characters including whitespace
CPunct - The ASCII printable non-blank non-alphanumeric characters
CSpace - ASCII whitespace: SPACE CR LF HT VT FF
CUpper - The 26 uppercase ASCII letters
CXdigit - Hexadecimal digits: 0123456789ABCDEFabcdef
CutBlanks - Remove blanks at begin and end of input string.
CutRegexMatch - Remove first or every match of given regular expression from a string
CutZeros - Remove any leading zeros
EscapeTags - Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.
FirstChunk - Shorthand for select (splitstring (s, separators), 0, "") Useful now that the above produces a deprecation warning.
FormatFilename - Format file name - truncate the middle part of the directory to fit to the reqested lenght. Path elements in the middle of the string are replaced by ellipsis (...). The result migth be longer that requested size if size of the last element (with ellipsis) is longer than the requested size. If the requested size is greater than size of the input then the string is not modified. The last part (file name) is never removed.
FormatRate - Return a pretty description of a download rate
FormatRateMessage - Add a download rate status to a message.
FormatSize - Return a pretty description of a byte count
FormatSizeWithPrecision - Return a pretty description of a byte count
GetCommentLines - Get comment without metadata
GetMetaDataLines - Get metadata lines from input string
NonEmpty -
OptFormat - Optional formatted text
OptParens - Optional parenthesized text
Pad - Add spaces after the text to make it long enough
PadZeros - Add zeros before the text to make it long enough.
ParseOptions - Parse string of values
ParseSysconfigComment - Parse metadata from a sysconfig comment
Quote - Quote a string with 's
Random - Make a random base-36 number. srandom should be called beforehand.
Replace - Replace substring in a string. All substrings source are replaced by string target.
TextTable - Function creates text table without using HTML tags. (Useful for commandline) Undefined option uses the default one.
UnQuote - Unquote a string with 's (quoted with quote)
UnderlinedHeader - Function returns underlined text header without using HTML tags. (Useful for commandline)
ValidCharsFilename - Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.
WrapAt - Returns text wrapped at defined margin. Very useful for translated strings used for pop-up windows or dialogs where you can't know the width. It controls the maximum width of the string so the text should allways fit into the minimal ncurses window. If you expect some long words, such us URLs or words with a hyphen inside, you can also set the additional split-characters to "/-". Then the function can wrap the word also after these characters. This function description was wrapped using the function String::WrapAt().
List of Global Variables
Remove blanks at begin and end of input string.
Function parameters
string input
Return value
string - stripped string
Remove first or every match of given regular expression from a string
Function parameters
string input
string regex
boolean glob
Return value
string - that has matches removed
Remove any leading zeros
Function parameters
string input
Return value
string - that has leading zeros removed
Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.
Function parameters
string text
Return value
string - escaped text
Shorthand for select (splitstring (s, separators), 0, "") Useful now that the above produces a deprecation warning.
Function parameters
string s
string separators
Return value
string - first component or ""
Format file name - truncate the middle part of the directory to fit to the reqested lenght. Path elements in the middle of the string are replaced by ellipsis (...). The result migth be longer that requested size if size of the last element (with ellipsis) is longer than the requested size. If the requested size is greater than size of the input then the string is not modified. The last part (file name) is never removed.
Function parameters
string file_path
integer len
Return value
string - Truncated file name
Example 85.
FormatFilename("/really/very/long/file/name", 15) -> "/.../file/name" FormatFilename("/really/very/long/file/name", 5) -> ".../name" FormatFilename("/really/very/long/file/name", 100) -> "/really/very/long/file/name"
Return a pretty description of a download rate
Function parameters
integer bytes_per_second
Return value
string - formatted string
Add a download rate status to a message.
Function parameters
string text
integer avg_bps
integer curr_bps
Return value
string - formatted message
Return a pretty description of a byte count
Function parameters
integer bytes
Return value
string - formatted string
Return a pretty description of a byte count
Function parameters
integer bytes
integer precision
boolean omit_zeroes
Return value
string - formatted string
Example 88.
FormatSizeWithPrecision(128, 2, true) -> "128 B" FormatSizeWithPrecision(4096, 2, true) -> "4 kB" FormatSizeWithPrecision(4096, 2, false) -> "4.00 kB" FormatSizeWithPrecision(1024*1024, 2, true) -> "1 MB"
Get comment without metadata
Function parameters
string input
Return value
string - Comment used as variable description
Get metadata lines from input string
Function parameters
string input
Return value
list<string> - Metadata lines in list
Function parameters
string s
Return value
list<string> - the items as a list, with empty lines removed
Optional formatted text
Function parameters
string f
string s
Return value
string - sformat (f, s) if s is neither empty or nil, else ""
Optional parenthesized text
Function parameters
string s
Return value
string - " (Foo)" if Foo is neither empty or nil, else ""
Add spaces after the text to make it long enough
Function parameters
string text
integer length
Return value
string - padded text
Add zeros before the text to make it long enough.
Function parameters
string text
integer length
Return value
string - padded text
Parse string of values
Function parameters
string options
map parameters
Return value
list<string> - List of strings
Parse metadata from a sysconfig comment
Function parameters
string comment
Return value
map<string, string> - parsed metadata
Quote a string with 's
Function parameters
string var
Return value
string - quoted string
Make a random base-36 number. srandom should be called beforehand.
Function parameters
integer len
Return value
string - random string of 0-9 and a-z
Replace substring in a string. All substrings source are replaced by string target.
Function parameters
string s
string source
string target
Return value
string - result
Function creates text table without using HTML tags. (Useful for commandline) Undefined option uses the default one.
Function parameters
list<string> header
list <list <string> > items
map <string, any> options
Return value
string - table Header: [ "Id", "Configuration", "Device" ] Items: [ [ "1", "aaa", "Samsung Calex" ], [ "2", "bbb", "Trivial Trinitron" ] ] Possible Options: horizontal_padding (for columns), table_left_padding (for table)
Unquote a string with 's (quoted with quote)
Function parameters
string var
Return value
string - unquoted string
Function returns underlined text header without using HTML tags. (Useful for commandline)
Function parameters
string header_line
integer left_padding
Return value
string - underlined header line
Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.
Return value
string - for ValidChars
Returns text wrapped at defined margin. Very useful for translated strings used for pop-up windows or dialogs where you can't know the width. It controls the maximum width of the string so the text should allways fit into the minimal ncurses window. If you expect some long words, such us URLs or words with a hyphen inside, you can also set the additional split-characters to "/-". Then the function can wrap the word also after these characters. This function description was wrapped using the function String::WrapAt().
Function parameters
string text
integer width
string split_string
Return value
string - wrapped string