Language-level Alias - string
String represents a fixed array of characters.
String is a very special class type in Julian. Its assignment behavior is copy-by-value, instead of copy-by-references. This means assigning a string SA
to string SB
would first create a bit-level copy of the value that SA
points to, then let the copy be pointed by SB
, discarding whatever SB
was previously referring.
String is immutable. The methods exposed by this class are for reading its contents in various ways, and if any manipulating is implied (such as trim), it always mean to create a new string as the result of manipulation. The original string instance always remains unchanged.
String is iterable. This means one can use foreach grammar on a string, or get a character out of string directly:for (char c : str) {
...
}
char c0 = str[0];
str[0] = 'a'; // This will not cause a runtime error, but won't have any effect either.
String supports concatenation operation by '+
', which can also be used along with values of other types, as long as at least one operand is string.
Parent Class
Parent Interfaces
Type | Name | Signature |
---|---|---|
field C | length | public const int length |
method | at | public var at(var) |
method | at | public void at(var, var) |
method | compare | public int compare(var) |
method | contains | public bool contains(var) |
method | endsWith | public bool endsWith(var) |
method | firstOf | public int firstOf(var) |
method S | fromBytes | public static String fromBytes(Byte[]) |
method S | fromBytes | public static String fromBytes(Byte[], String, int, int) |
method S | fromChars | public static String fromChars(Char[]) |
method | getIterator | public System.Util.IIterator getIterator() |
method | indexOf | public int indexOf(var, int) |
method S | isEmpty | public static bool isEmpty(String) |
method | lastIndexOf | public int lastIndexOf(var, int) |
method | replace | public String replace(String, String) |
method | size | public int size() |
method | split | public String[] split(var) |
method | startsWith | public bool startsWith(var) |
method | substring | public String substring(int, int) |
method | toBytes | public byte[] toBytes() |
method | toBytes | public byte[] toBytes(String) |
method | toChars | public char[] toChars() |
method | toLower | public String toLower() |
method | toUpper | public String toUpper() |
method | trim | public String trim() |
public const int length
The length of this string.
public var at(var index)
Get the character at specified index.
This is the implementation of getter method on System.Util.IIndexble.
Parameters
Returns
Throws
public void at(var index, var value)
This method is implemented for System.Util.IIndexble, but due to the immutability of string it will do nothing.
Parameters
public int compare(var another)
Compare this string against another value, which can be either a string or a char. If the other value is neither string nor char, returns 0.
This method implements System.Util.IComparable.
Parameters
Returns
public bool contains(var search)
Check if the string contains the given string or character.
Parameters
Returns
Throws
public bool endsWith(var suffix)
Check if the string is ended with the given string or character.
Parameters
Returns
Throws
public int firstOf(var search)
Get the starting index (0-based) of the first occurence of the given string or character within this string.
To search only within a certain scope of this string, call indexOf() instead.
Parameters
Returns
Throws
public static String fromBytes(byte[] bytes)
Create a string from an array of bytes in ASCII encoding.
Parameters
Returns
Throws
public static String fromBytes(byte[] bytes, String charset, int offset, int length)
Create a string from an array of bytes in specified encoding.
Parameters
Returns
Throws
public static String fromChars(char[] chars)
Create a string from an array of chars.
Parameters
Returns
Throws
public IIterator getIterator()
Get an iterator from this string. The iterator produces characters which consist of this string.
This is the implementation of System.Util.IIterable.
Returns
public int indexOf(var search, int offset)
Get the starting index (0-based) of the first occurence of the given string or character within this string.
If only checking for the existence within the entire string, consider using contains() instead.
Parameters
Returns
Throws
public static bool isEmpty(String str)
Check if the string is null or empty (containing no characters).
Parameters
Returns
public int lastIndexOf(var search, int offset)
Get the starting index (0-based) of the last occurence of the given string or character within this string.
If only checking for the existence within the entire string, consider using contains() instead.
Parameters
Returns
Throws
public String replace(String oldStr, String newStr)
Replace all occurences of a substring with another one.
Parameters
Returns
public int size()
Get the length of the string.
This is the implementation of size()
method on System.Util.IIndexble. This is equivalent to length field.
Returns
public String[] split(var splitter)
Split the string into multiple substrings at the specified boundary.
Parameters
Returns
public bool startsWith(var prefix)
Check if the string is started with the given string or character.
Parameters
Returns
Throws
public String substring(int start, int end)
Get a substring out of this string.
Parameters
Returns
Throws
public byte[] toBytes()
Convert this string to an array of bytes in ASCII encoding.
Returns
public byte[] toBytes(String charset)
Convert this string to an array of bytes using specified charset.
Parameters
Returns
Throws
public char[] toChars()
Convert this string to a char array.
Returns
public String toLower()
Convert the string to lower case.
Returns
public String toUpper()
Convert the string to upper case.
Returns
public String trim()
Trim the start and end of this tring, removing all the leading and trailing blank chracacters.
Blank characters are line feed (\r), carriage return (\n), horizontal tabulation (\t) and space ( ).
Returns