Class String

Class string is a variable size sequence of Unicode characters.

There are many methods in string class: You may compare two strings. You may search, add, and remove a character or a string from it. You may replace a character or string with another character or string. There are special operations as well: You may split a string into an array of substrings separated by separator, which may be a new line, for instance. You may convert a string to upper or lower case letters or convert an integer an value to string format and vice versa.

CONSTRUCTION

COMPARISION

SIZE

REFERENCE & ASSIGNEMENT

SEARCH OF DATA

STATISTICS

INSERTION

REPLACEMENT

REMOVAL

OTHER


(string) copy

Create a new string from 'this'.

Return value

Example

main
  string s = "ab".copy
  print s  // LOG: "ab"
        

(string) new string from <char c> [ size <int n = 1> ]

Create a new string of length 'n', all characters having value 'c'.

Parameters

Return value

Exceptions

Example

main
  string s = new string from 'b' size 10
  print s // LOG: "bbbbbbbbbb"
        

(stringview) <ref string> [ ]

Create new stringview to a part of string.

Parameters

Return value

<string s> [ <range r> ] = <string s2>

Modifies a string with a given range (Insert/remove/replace/clear).

Parameters

(string) <string s> & <string t>

Create a new string by concatenating string 's' and 't'.

Parameters

Return value

Example

main
  print "ab" & "cd" // LOG: "abcd"
        

(string) <string s> * <int n>

Create a new string that contains 'n' successive copies of 's'.

Parameters

Return value

Exceptions

Example

main
  string s = "ab" * 3
  print s // LOG: "ababab"
        

(string[]) split by <string separator> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Split 'this' into an array of substrings separated by 'separator'. The separators found are not included in the substrings. If a substring is empty, it's not included in the array. Use this method for instance, if you want to split a text document into an array of rows (separated by new line).

Parameters

Return value

Exceptions

Example

main
  string[] sv =  "ab-cd--ef".split by "-"
  print sv[0] // LOG: "ab"
  print sv[1] // LOG: "cd"
  print sv[2] // LOG: "ef"
        

(compareresult) compare to <string s2> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Compare 'this' or optionally, a range of 'this' to 's'.

Parameters

Return value

Example


main
  compareResult v

  v = "aa".compare to "aa"
  if v == EQUAL
    print "Equal"                                           // LOG: Equal

  v = "aa".compare to "AA" compare mode CASE SENSITIVE
  if v != EQUAL
    print "Not equal"                                       // LOG: Not equal

  v = "c".compare to "cc"
  if v == LESS THAN
    print "Less than"                                       // LOG: "Less than"

  v = "c".compare to "bb"
  if v == GREATER THAN
    print "Greater than"                                    // LOG: "Greater than"
      

(bool) equals to <string s> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Check the equality. This is faster than method compare, is just equality is interesting. Optionally you may give a range for 'this'.

Parameters

Return value

Example

main
  bool b

  b = "".equals to ""
  if b
    print "true"                         // LOG: "true"

  b = "aa".equals to "aa"
  if b
    print "true"                         // LOG: "true"

  b = "aa".equals to "AA"
  if not b
    print "false"                        // LOG: "false"

  b = "aa".equals to "AA" compare mode CASE INSENSITIVE
  if b
    print "true"                         // LOG: "true"

        

(bool) <string s> == <string t>

Check the equality.

Parameters

Return value

Example

main
  if "aa" == "aa"
    print "==" // LOG: "=="
        

(bool) <string s> != <string t>

Check the inequality.

Parameters

Return value

Example

main
  if "aa" != "bb"
    print "!=" // LOG: "!="
      

(bool) <string s> < <string t>

Comparision.

Parameters

Return value

Example

main
  if "aa" < "aaa"
    print "<" // LOG: "<"
      

(bool) <string s> <= <string t>

Comparision.

Parameters

Return value

Example

main
  if "aa" <= "aaa"
    print "<=" // LOG: "<="

  if "aa" <= "aa"
    print "<=" // LOG: "<="
      

(bool) <string s> > <string t>

Comparision.

Parameters

Return value

Example

main
  if "bb" > "b"
    print ">" // LOG: ">"

  if "c" > "b"
    print ">" // LOG: ">"
      

(bool) <string s> >= <string t>

Comparision.

Parameters

Return value

Example

main
  if "bb" >= "b"
    print ">" // LOG: ">="

  if "c" >= "c"
    print ">" // LOG: ">="
      

(int) get size

Query size of 'this'.

Return value

Example

main
  print "".get size   // LOG: 0
  print "ab".get size // LOG: 2
        

(char) <string s> [ <int v> ]

Query the character value at the specified position 'v'.

Parameters

Return value

Exceptions

Example

main
  string s = "abc"
  print s[1] // LOG: b
      

(int) <string s>.find first <string occurrence> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Search the first occurrence of a string or character. Optionally you may limit the search in a range.

Parameters

Return value

Example

main
  int result
  string s = "abcabcabc"

  result = s.find first ""
  // result == -1

  result = s.find first "x"
  // result == -1

  result = s.find first "bc"
  // result ==  1

  result = s.find first "BC"
  // result == 1

  result = s.find first "BC" compare mode CASE SENSITIVE
  // result == -1

  result = s.find first s
  // result == 0

      

(int) find last <string occurrence> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Search the last occurrence of a string or character. Optionally you can set compare mode.

Parameters

Return value

Example

main
  int result
  string s = "abcabcabc"

  result = s.find last ""
  // result = -1

  result = s.find last "x"
  // result = -1

  result = s.find last "bc"
  // result = 7

  result = s.find last "BC"
  // result = 7

  resultRange = s.find last "BC" compare mode CASE SENSITIVE
  // result = -1

  result = s.find last s
  // result = 0

      

<string s> &= <string c>

Append. Insert the character 'c' or string 's ' at end.

Parameters

Example

main
  string s = "ab"
  s &= "cd"
  print s          // LOG: "abcd"

  s &= ""
  print s          // LOG: "abcd"
        

<string s> *= <int n>

Append itself 'n' - 1 times.

Parameters

Exceptions

Example

main
  string s = "ab"
  s *= 3
  print s          // LOG: "ababab"
        

<string s>.replace every <string occurrence> with <string s2> [ compare mode <StringCompareMode b = CASE INSENSITIVE> ]

Replace every 'occurrence' in 'this' with a string 's' or character 'c'. Optionally you may set compare mode.

Parameters

Example

       main
         string s = "azzbzzc"

         s.replace every "zz" with "-"
         print s                                        // LOG: "a-b-c"

s = "azzbzzc"
         s.replace every "ZZ" with "-" compare mode CASE SENSITIVE
         print s                                        // LOG: "azzbzzc"
               

remove <int v>

Remove character at position 'v' from 'this'.

Parameters

Exceptions

Example

main
  string s = "abcd"

  s.remove 2
  print s                              // LOG: "abd"

  s.remove 2
  print s                              // LOG: "ab"
        

to lower case

Convert characters of 'this' to lower case using Unicode rules.

Example

main
  string s = "ABC"
  s.to lower case
  print s  // LOG: "abc"
      

to upper case

Convert characters of 'this' to upper case using Unicode rules.

Example

main
  string s = "abc"
  s.to upper case
  print s  // LOG: "ABC"
      

(int) as int [ base <int n = 10> ]

The method converts the number in 'this' to integer. The number is supposed to be in base 'n' format. The method accepts leading white-spaces. With base 10 (decimal base) it accepts also the minus sign as a mark of a negative number. The method stops reading the string at the first character that it cannot recognize as part of a number.

Parameters

Return value

Exceptions

Example

main
  string s
  int v

  s = " -1234"
  v = s.as int
  print v   // LOG: -1234

  s = " 1234"
  v = s.as int base 10
  print v   // LOG: 1234

  s = "101110011"
  v = s.as int base 2
  print v   // LOG: 371

  s = "FFFA"
  v = s.as int base 16
  print v   // LOG: 65530