Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

String

String defines several useful functions for string manipulation. The following list gives a short overview:

  • strip(string* pointer): Removes all whitespaces from a string. See getStripped for examples.
  • getStripped(string): Removes all whitespaces and returns the modified string.
    • Example: getStripped(" test abc\tabc test\nThis is a newline! ") = "testabcabctestThisisanewline!"
  • removeTrailingWhitespaces(string): Removes trailing whitespace and returns the modified string.
    • Example: removeTrailingWhitespaces(" test abc ") = "test abc"
  • getNextQuote(string, start): Returns the position of the next quote in the string, starting with start.
    • Examples:
      • getNextQuote("012\"456\"89", 0) = 3
      • getNextQuote("012\"456\"89", 3) = 3
      • getNextQuote("012\"456\"89", 5) = 7
      • getNextQuote("012\"456\"89", 8) = std::string::npos
  • isBetweenQuotes(string, position): Returns true if position is between two quotes.
    • Examples:
      • isBetweenQuotes("012\"456\"89", 0) = false
      • isBetweenQuotes("012\"456\"89", 3) = false
      • isBetweenQuotes("012\"456\"89", 4) = true
      • isBetweenQuotes("012\"456\"89", 7) = false
      • isBetweenQuotes("012\"456\"89", 8) = false
  • hasStringBetweenQuotes(string): Returns true if the string contains something like '…"between quotes"…'.
    • Examples:
      • hasStringBetweenQuotes("test") = false
      • hasStringBetweenQuotes("test\"abc") = false
      • hasStringBetweenQuotes("test\"abc\"") = true
  • getStringBetweenQuotes(string): If the string contains something like '…"between quotes"…' then 'between quotes' gets returned (without quotes).
    • Examples:
      • hasStringBetweenQuotes("test") = ""
      • hasStringBetweenQuotes("test\"abc") = ""
      • hasStringBetweenQuotes("test\"abc\"") = "abc"
  • stripEnclosingQuotes(string): Removes enclosing quotes if available (including whitespaces at the outside of the quotes).
    • Examples:
      • stripEnclosingQuotes(" \"hello!\" ") = "hello!"
      • stripEnclosingQuotes(" \"hello! ") = " \"hello! "
  • stripEnclosingBraces(string): Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string).
    • Examples:
      • stripEnclosingBraces("{test}") = "test"
      • stripEnclosingBraces(" {test}") = " {test}"
      • stripEnclosingBraces("{ test }") = " test "
  • isEmpty(string): Determines if a string is empty (contains only whitespaces (' ', \t, \n).
  • isComment(string): Determines if a string is a comment (starts with a comment-symbol). A comment is defined by a leading '#', '%', ';' or ''.
    • Examples:
      • isComment("# test") = true
      • isComment("a # test") = false
      • isComment(" # test") = true
  • isNumeric(string): Determines if a string contains only numbers and maximal one '.'.
  • addSlashes(string): Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled.
    • Examples: "\\""\\\\", "\n""\\n"
  • removeSlashes(string): Removes backslashes from the given string. Double backslashes are interpreted as one backslash.
    • Examples: "\\\\""\\", "\\n""\n"
  • lowercase(string* pointer): Replaces each char between A and Z with its lowercase equivalent. Uses tolower (C function).
  • getLowercase(string): Returns a copy of the given string without uppercase chars.
  • uppercase(string* pointer): Replaces each char between a and z with its uppercase equivalent. Uses toupper (C function).
  • getUppercase(string): Returns a copy of the given string without lowercase chars.
  • nocaseCmp(string1, string2): Compares two strings ignoring different casing.
  • nocaseCmp(string1, string2, length): Compares the first 'len' chars of two strings ignoring different casing.
  • hasComment(string): Returns true if the string contains a comment, introduced by #, %, ; or .
    • Examples:
      • hasComment("test") = false
      • hasComment("# test") = true
      • hasComment(" # test") = true
      • hasComment("a # test") = true
  • getComment(string): If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise.
    • Example: getComment("abc # test") = "# test"
  • getCommentPosition(string): If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise.
    • Examples:
      • getCommentPosition("# test") = 0
      • getCommentPosition("abc # test") = 4
      • getCommentPosition("abc test") = std::string::npos
  • getNextCommentPosition(string, start): Returns the position of the next comment-symbol, starting with start.
    • Examples:
      • getCommentPosition("abc # test", 0) = 4
      • getCommentPosition("abc # test", 4) = 4
      • getCommentPosition("abc # test", 5) = std::string::npos
Last modified 8 years ago Last modified on Apr 12, 2017, 11:35:40 PM