228. String

String manipulation routines

228.1. Summary of Module Globals

List of Global Functions

  • CAlnum -

  • CAlpha -

  • CDigit -

  • CGraph -

  • CLower -

  • CPrint -

  • CPunct -

  • CSpace -

  • CUpper -

  • CXdigit -

  • 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.

  • 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

  • NewlineItems -

  • 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

    228.2. Global Functions

    228.2.1. CAlnum

    Return value

    • string - the 52 upper and lowercase ASCII letters and digits

    228.2.2. CAlpha

    Return value

    • string - the 52 upper and lowercase ASCII letters

    228.2.3. CDigit

    Return value

    • string - 0123456789

    228.2.4. CGraph

    Return value

    • string - printable ASCII charcters except whitespace

    228.2.5. CLower

    Return value

    • string - the 26 lowercase ASCII letters

    228.2.6. CPrint

    Return value

    • string - printable ASCII characters including whitespace

    228.2.7. CPunct

    Return value

    • string - the ASCII printable non-blank non-alphanumeric characters

    228.2.8. CSpace

    Return value

    • string - ASCII whitespace

    228.2.9. CUpper

    Return value

    • string - the 26 uppercase ASCII letters

    228.2.10. CXdigit

    Return value

    • string - hexadecimal digits: 0123456789ABCDEFabcdef

    228.2.11. CutBlanks

    Remove blanks at begin and end of input string.

    Function parameters

    • string input

    Return value

    • string - stripped string

    Example 63. 

     CutBlanks("  any  input     ") -> "any  input"


    228.2.12. CutRegexMatch

    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

    228.2.13. CutZeros

    Remove any leading zeros

    Function parameters

    • string input

    Return value

    • string - that has leading zeros removed

    228.2.14. EscapeTags

    Function for escaping (replacing) (HTML|XML...) tags with their (HTML|XML...) meaning.

    Function parameters

    • string text

    Return value

    • string - escaped text

    228.2.15. FirstChunk

    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 ""

    228.2.16. FormatSize

    Return a pretty description of a byte count

    Function parameters

    • integer bytes

    Return value

    • string - formatted string

    Example 64. 

     FormatSize(23456767890) -> "223.70 MB"


    228.2.17. FormatSizeWithPrecision

    Return a pretty description of a byte count

    Function parameters

    • integer bytes

    • integer precision

    • boolean omit_zeroes

    Return value

    • string - formatted string

    Example 65. 

     FormatSizeWithPrecision(4096, 2, true) -> "4 KB"
     FormatSizeWithPrecision(4096, 2, false) -> "4.00 KB"


    228.2.18. GetCommentLines

    Get comment without metadata

    Function parameters

    • string input

    Return value

    • string - Comment used as variable description

    228.2.19. GetMetaDataLines

    Get metadata lines from input string

    Function parameters

    • string input

    Return value

    • list<string> - Metadata lines in list

    228.2.20. NewlineItems

    Function parameters

    • string s

    Return value

    • list<string> - the items as a list, with empty lines removed

    228.2.21. NonEmpty

    Function parameters

    • list<string> l

    Return value

    • list<string> - only non-"" items

    228.2.22. OptFormat

    Optional formatted text

    Function parameters

    • string f

    • string s

    Return value

    • string - sformat (f, s) if s is neither empty or nil, else ""

    228.2.23. OptParens

    Optional parenthesized text

    Function parameters

    • string s

    Return value

    • string - " (Foo)" if Foo is neither empty or nil, else ""

    228.2.24. Pad

    Add spaces after the text to make it long enough

    Function parameters

    • string text

    • integer length

    Return value

    • string - padded text

    228.2.25. PadZeros

    Add zeros before the text to make it long enough.

    Function parameters

    • string text

    • integer length

    Return value

    • string - padded text

    228.2.26. ParseOptions

    Parse string of values

    Function parameters

    • string options

    • map parameters

    Return value

    • list<string> - List of strings

    228.2.27. ParseSysconfigComment

    Parse metadata from a sysconfig comment

    Function parameters

    • string comment

    Return value

    • map<string, string> - parsed metadata

    228.2.28. Quote

    Quote a string with 's

    Function parameters

    • string var

    Return value

    • string - quoted string

    Example 66. 

     quote("a'b") -> "a'\''b"


    228.2.29. Random

    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

    228.2.30. Replace

    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

    228.2.31. TextTable

    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)

    228.2.32. UnQuote

    Unquote a string with 's (quoted with quote)

    Function parameters

    • string var

    Return value

    • string - unquoted string

    228.2.33. UnderlinedHeader

    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

    228.2.34. ValidCharsFilename

    Characters valid in a filename (not pathname). Naturally "/" is disallowed. Otherwise, the graphical ASCII characters are allowed.

    Return value

    • string - for ValidChars

    228.2.35. 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().

    Function parameters

    • string text

    • integer width

    • string split_string

    Return value

    • string - wrapped string

    Example 67. 

     String::WrapAt("Some very long text",30,"/-");
    


    228.3. Global Variables

    228.4. Module Requirements

    none