libperun

Class std.rt.String

Synopsis

public final class String extends Comparable< String >

Represents strings of characters.

Fields

public static final String[] LOWERCASE_DIGITS

Lower-case digits for fromInt(). There are 36 digits in this array, thus making the maximum radix 36.

public static final String[] UPPERCASE_DIGITS

Upper-case digits for fromInt(). There are 36 digits in this array, thus making the maximum radix 36.

Constructors

Methods

public static String fromCodePoint(qword_t point);

Make a string containing a single UTF-8 character.

public static String fromBool(bool value);

Make a string from a boolean.

Arguments
valueThe boolean value.
Returns

Either the string "true" or the string "false".

public static String fromFloat(double value,int minPrecision,int maxPrecision,bool allowExp);

Make a string from a floating-point number.

Arguments
valueThe value to be converted into a string.
minPrecisionThe minimum number of digits after the demical point to display.
maxPrecisionThe mximum number of digits after the decimal point to display.
allowExpIf true, write the number in standard form if very small.
Returns

The resulting string.

public static String fromFloat(double value,int minPrecision,int maxPrecision);

Make a string from a floating-point number. If the number is very small, it'll be converted to standard form.

Arguments
valueThe value to be converted into a string.
minPrecisionThe minimum number of digits after the demical point to display.
maxPrecisionThe mximum number of digits after the decimal point to display.
Returns

The resulting string.

public static String fromFloat(double value);

Make a string from a floating-point number. If the number is very small, it'll be converted to standard form.

Arguments
valueThe value to be converted into a string.
Returns

The resulting string.

public static String fromInt(int value,int radix,String[] digits);

Make a string from an integer.

Arguments
valueThe number to be converted into a string.
radixThe radix (base) of the number system to use.
digitsThe array of digits to use. The lenght must be at least radix.
public static String fromInt(int value,int radix);

Make a string from an integer. If the radix is larger than 10, then lowercase letters will be used as the extra digits. The maximum radix is thus 36.

Arguments
valueThe number to be converted into a string.
radixThe radix (base) of the number system to use.
public static String fromInt(int value);

Make a base-10 string from an integer.

Arguments
valueThe value to be converted into a string.
public static String fromInt(dword_t value,int radix,String[] digits);

Make a string from an unsigned integer.

Arguments
valueThe value to be converted into a string.
radixThe radix (base) of the number system to use.
digitsThe digits to use; the length must be at least radix.
public static String fromInt(dword_t value,int radix);

Make a string from an integer. If the radix is larger than 10, then lowercase letters will be used as the extra digits. The maximum radix is thus 36.

Arguments
valueThe number to be converted into a string.
radixThe radix (base) of the number system to use.
public static String fromInt(dword_t value);

Make a base-10 string from an integer.

Arguments
valueThe value to be converted into a string.
public static String fromByteArray(byte_t[] bytes,int offset,int count);

Make a string from an array of bytes.

Arguments
bytesThe array of bytes.
offsetOffset into the array to begin copying characters from.
countNumber of characters to copy.
public int size();

Return the size of the string.

Returns

The size of the string (in bytes).

public String opAdd(String other);

Concatenate two strings; implements the + operator.

public String opAdd(int value);

Concatenate a string with an integer. The integer is converted to a string in base 10 before being concatenated.

public String opAdd(dword_t value);

Concatenate a string with an integer. The integer is converted to a string in base 10 before being concatenated.

public String opAdd(bool value);

Concatenate a string with a boolean.

public String opAdd(double value);

Concatenate a string with a floating-point number.

public bool opEquals(Object b);

Check if two strings are equal.

public int opCompare(String s);

No description given

public dword_t hash();

Compute the hash of a string.

public String opAdd(StringFormattable formattable);

Concatenate a string with a StringFormattable object.

public byte_t[] toByteArray();

Convert the string to an array of bytes making up the string.

public byte_t[] toByteArrayWithTerminator();

Convert the string to an array of bytes making up the string, NUL-terminated.

public String substr(int start,int size);

Extract a substring from this string.

Arguments
startThe starting position (zero-based) to begin extracting from.
sizeNumber of bytes to extract.
Throws
IndexErrorIf the range is out of bounds.
public String substr(int start);

Extract a substring from start to the end of this string.

Arguments
startThe starting position (zero-based) to begin extracting from.
Throws
IndexErrorIf the starting position is out of bounds.
public int find(String sub,int start);

Find a substring inside this string, and return its offset, but only if found after start. Returns -1 if the string is not found.

public int find(String sub);

Find a substring inside this string, and return its offset. Returns -1 if the string is not found.

public int find(Pattern pat,int start);

Find a substring matching the specified pattern inside this string, and return its offset, but only if found after start. Returns -1 if the string is not found.

public int find(Pattern pat);

Find a substring matching the specified pattern inside this string. Returns -1 if not found.

public int count(String sub);

Count the number of occurences of sub within this string.

public bool startsWith(String prefix);

Returns true if this string starts with prefix.

public bool endsWith(String suffix);

Returns true if this strings ends with suffix.

public String replace(String search,String replaceWith);

Return this string, but with all occurences of search replaced with replaceWith.

public String replace(Pattern pat,String format);

Return this string, but with all substrings matching pat replaced with format, which is a regex format string. See std.re.Match.format() for more information.

public String[] split(String delimiter,int maxSplits);

Split the string at the specified delimiter, up to the maximum number of splits, and return an array with all tokens which were delimited by the specified delimiter in the original string. The final token contains the remainder of the string, if there were more occurences of the delimeter than the maximum.

Arguments
delimiterThe delimiter which is to split the tokens.
maxSplitsMaximum number of splits; the returned array will have one more elements than this number. A value of 0 indicates that there should not be any splits, and the full string is returned as the sole member of the array. Negative values indicate that there is no limit to splits.
Returns

An array containing the delimited tokens.

Throws
std.rt.IllegalArgumentErrorIf delimeter is the empty string.
public String[] split(String delimiter);

Split the string at the specified delimiter, up to the maximum number of splits, and return an array with all tokens which were delimited by the specified delimiter in the original string.

Arguments
delimiterThe delimiter which is to split the tokens.
Returns

An array containing the delimited tokens.

Throws
std.rt.IllegalArgumentErrorIf delimeter is the empty string.
public dword_t parseUnsignedInt();

Convert the string to an unsigned integer.

public int parseInt();

Convert the string to a signed integer.

public double parseFloat();

Convert the string to a floating-point number, of type double.

public String join(String[] array);

Join an array of strings, using this one as a delimiter between them.