String

Summary

The wrapper class for the string primitive type.

Description

The System.String class represents sequences of characters, known as "strings". The System.String class is the wrapper class for the string primitive type.

All string literals are implemented as instances of the System.String class.

Differences to JavaScript

  • match() will never return null. If there are no matches, an empty array is returned.
  • JS++ does not implement a String.substr() method because it causes confusion with String.substring(). Instead, String.substringFor() is the JS++ equivalent of the JavaScript String.prototype.substr()
  • localeCompare() is not implemented. Use Externals.JS.String.prototype.localeCompare instead.
  • search() is not implemented. It's just indexOf() using regular expressions, so indexOf() has been overloaded to take a regex.

Examples

Instantiation
1
2
3
import System;
 
System.String str = new System.String("abc");
Auto-boxing
1
2
3
import System;
 
System.String str = "abc";
Primitives Only
1
string str = "abc";

Methods

  • append

    Inserts the specified text at the end of the string.

  • between

    Matches all substrings between two delimiters.

  • charAt

    Extracts the character from a given position in the string.

  • charCodeAt

    Gets the Unicode value of a character at a given position.

  • compact

    Removes all whitespace from the string.

  • compare

    Compares the String object to another String object.

  • concat

    Concatenates two strings together.

  • contains

    Checks if the string contains the specified substring.

  • count

    Counts the occurrences of the specified substring in the string.

  • countLines

    Counts the number of lines in the string (including empty lines).

  • countNonEmptyLines

    Counts the number of non-empty lines in the string.

  • EMPTY

    A constant field that represents an empty string.

  • endsWith

    Checks if the string ends with the specified substring.

  • escape

    Escapes JS++ escape sequences with a preceding backslash.

  • escapeQuotes

    Escapes all double and single quotes.

  • format

    Replaces formatting sequence(s) with their corresponding argument(s).

  • fromCharArray

    Constructs a new string from an array of character values.

  • fromCharCode

    Returns a string based on a sequence of Unicode values.

  • icontains

    Checks if the string contains the specified substring by performing a case-insensitive search.

  • icount

    Counts the occurrences of the specified substring in the string while ignoring case.

  • indexOf

    Gets the first position a substring occurs at or regular expression matches at.

  • insert

    Inserts a substring at the specified position in the string.

  • isEmpty

    Checks if the string contains no characters.

  • isLowerCase

    Checks if the alphabetical characters in the string are lowercase letters.

  • isUpperCase

    Checks if the alphabetical characters in the string are uppercase letters.

  • isWhitespace

    Checks if the string is composed entirely of whitespace characters.

  • joinLines

    Condenses multiple lines of text into a single line.

  • joinNonEmptyLines

    Condenses multiple non-empty lines of text into a single line of text.

  • lastIndexOf

    Gets the last position a substring occurs at or regular expression matches at.

  • length

    Returns the number of characters in the string.

  • match

    Finds a substring or matches for a regular expression.

  • padLeft

    Pads the string with spaces from the left until it reaches the specified width (number of characters).

  • padRight

    Pads the string with spaces from the right until it reaches the specified width (number of characters).

  • prepend

    Inserts the specified text to the beginning of the string.

  • quote

    Wraps the string in double quotes.

  • quoteSingle

    Wraps the string in single quotes.

  • repeat

    Repeats the string the specified number of times.

  • replace

    Performs a regular expression search over the string and replaces the matched pattern(s) with the specified replacement string.

  • reverse

    Reverses the string.

  • slice

    Extracts a substring from the given position(s).

  • split

    Divides the string into substrings, optionally separated by a delimiter.

  • splitLines

    Splits the string into individual lines and returns the resulting lines in an array.

  • startsWith

    Checks if the string begins with the specified substring.

  • String (Constructor)

    Constructs a System.String object.

  • substring

    Extracts a substring.

  • substringFor

    Extract a substring for a specified number of characters.

  • toCharArray

    Constructs a character array from the string value.

  • toLowerCase

    Converts each character of the string to lowercase.

  • toString

    Returns the string value.

  • toUpperCase

    Converts each character of the string to uppercase.

  • trim

    Removes whitespace from the beginning and end of the string.

  • trimLeft

    Removes whitespace from the beginning of the string.

  • trimMulti

    Removes whitespace from thje beginning and end of each line of the string.

  • trimMultiLeft

    Removes leading whitespace from the beginning of each line of the string without removing newline characters.

  • trimMultiRight

    Removes trailing whitespace from the end of each line of the string without removing newline characters.

  • trimRight

    Removes whitespace from the end of the string.

  • truncate

    Cuts off the string at the specified length (number of characters).

  • unescape

    Removes prefixed backslashes to produce equivalent escape sequences from the result.

  • unescapeQuotes

    Removes the leading backslash from all escaped double and single quotes.

  • unquote

    Removes quotation marks (double and single).

  • valueOf

    Returns the primitive string value wrapped by the System.String object.

Share

HTML | BBCode | Direct Link