|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmoka.lang.Object
moka.lang.String
The String
class represents character strings. All
string literals in Moka programs, such as "abc"
, should be
implemented as instances of this class for easy manipulation.
Strings are not constant; their values can be changed after they are created. Because String objects are mutable they can't be shared. For example:
String str = "abc";
is not equivalent to:
char[] chars = {'a', 'b', 'c', '\0'}; String str = new String(chars);
The class String
includes methods for examining
individual characters of the sequence, for comparing strings, for
searching strings, for extracting substrings, and for creating a
copy of a string with all characters translated to uppercase or to
lowercase.
String conversions are implemented through the method
toString
, defined by Object
and
inherited by all classes in Moka.
Constructor Summary | |
String()
Initializes a newly created String object so that it
represents an empty character sequence. |
|
String(char_p ansiString)
Initializes a newly created String object so that its
value makes reference to a given ANSI string. |
|
String(char_p ansiString,
boolean ref)
Initializes a newly created String object so that its
value makes reference or not to a given ANSI string. |
|
String(String original)
Initializes a newly created String object so that it
represents the same sequence of characters as the argument; in other
words, the newly created string is a copy of the argument string. |
Method Summary | |
String |
append(boolean b)
Appends the string representation of the boolean
argument to the string. |
String |
append(byte b)
Appends the string representation of the byte
argument to this string. |
String |
append(char_p str,
int offset,
int len)
Appends the characters of a subarray of the char array argument to this string. |
String |
append(char c)
Appends the string representation of the char
argument to this string. |
String |
append(double d)
Appends the string representation of the double
argument to this string. |
String |
append(int i)
Appends the string representation of the int
argument to this string. |
String |
append(long l)
Appends the string representation of the long
argument to this string. |
String |
append(Object obj)
Appends the string representation of the Object
argument to this string. |
String |
append(short s)
Appends the string representation of the short
argument to this string. |
String |
append(String str)
Appends the string to this string. |
char |
charAt(int index)
Returns the character at the specified index. |
short |
compareTo(String anotherString)
Compares two strings lexicographically. |
String |
concat(String str)
Concatenates the specified string to the end of this string. |
String |
delete(int start,
int end)
Removes the characters in a substring of this String . |
boolean |
endsWith(String suffix)
Tests if this string ends with the specified suffix. |
boolean |
equals(Object object)
Compares this string to the specified object. |
boolean |
equalsIgnoreCase(String anotherString)
Compares this String to another String ,
ignoring case considerations. |
void |
finalize()
Frees the memory of system ressources used by this String object. |
void |
getChars(int srcBegin,
int srcEnd,
char_p dst,
int dstBegin)
Copies characters from this string into the destination character array. |
int |
indexOf(String str,
int fromIndex)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. |
int |
lastIndexOf(String str,
int fromIndex)
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index. |
int |
length()
Returns the length of this string. |
boolean |
regionMatches(boolean ignoreCase,
int toffset,
String other,
int ooffset,
int len)
Tests if two string regions are equal. |
boolean |
regionMatches(int toffset,
String other,
int ooffset,
int len)
Tests if two string regions are equal. |
String |
replace(char oldChar,
char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar . |
String |
replace(String oldStr,
String newStr)
Returns a new string resulting from replacing all occurrences of oldStr substring in this string with newStr . |
boolean |
startsWith(String prefix,
int toffset)
Tests if this string starts with the specified prefix beginning a specified index. |
short |
strcmp(char_p ansiString)
Compares two strings lexicographically. |
String |
substring(int beginIndex,
int endIndex)
Returns a new string that is a substring of this string. |
String |
toLowerCase()
Converts all of the characters in this String to lower
case. |
String |
toString()
Returns a copy of this string. |
String |
toUpperCase()
Converts all of the characters in this String to upper
case. |
char_p |
toVat()
Converts this String object to a TIOS VAT String. |
String |
trim()
Returns this string, minus the leading and trailing whitespace. |
static String |
valueOf(boolean b)
Returns the string representation of the boolean argument. |
static String |
valueOf(byte b)
Returns the string representation of the byte argument. |
static String |
valueOf(char_p ansiString)
Returns the string representation of the ANSI string argument. |
static String |
valueOf(char_p data,
int length)
Returns the string representation of the char array
argument. |
static String |
valueOf(char c)
Returns the string representation of the char argument. |
static String |
valueOf(double d)
Returns the string representation of the double argument. |
static String |
valueOf(int i)
Returns the string representation of the int argument. |
static String |
valueOf(long l)
Returns the string representation of the long argument. |
static String |
valueOf(short s)
Returns the string representation of the short argument. |
static String |
valueOf(UByte b)
Returns the string representation of the ubyte argument. |
static String |
valueOf(UInteger i)
Returns the string representation of the uint argument. |
static String |
valueOf(ULong l)
Returns the string representation of the ulong argument. |
static String |
valueOf(UShort s)
Returns the string representation of the ushort argument. |
Methods inherited from class moka.lang.Object |
getClassName |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public String()
String
object so that it
represents an empty character sequence.
public String(String original)
String
object so that it
represents the same sequence of characters as the argument; in other
words, the newly created string is a copy of the argument string.
original
- a String
.public String(char_p ansiString)
String
object so that its
value makes reference to a given ANSI string.
ansiString
- an ANSI string.public String(char_p ansiString, boolean ref)
String
object so that its
value makes reference or not to a given ANSI string.
ansiString
- an ANSI string.ref
- true if the value is a reference, false otherwise.Method Detail |
public String append(Object obj)
Object
argument to this string.
The argument is converted to a string as if by its method
toString
, and the characters of that
string are then appended to this string.
obj
- an Object
.
String
object.public String append(String str)
The characters of the String
argument are appended, in
order, to the contents of this string, increasing the
length of this string buffer by the length of the argument. If the string object
risk to be used later,use a copy of the string object
instead of the original, the string being finalized before the method returns.
str
- a string.
String
.public String append(char_p str, int offset, int len)
char
array argument to this string.
Characters of the character array str
, starting at
index offset
, are appended, in order, to the contents
of this string. The length of this string increases
by the value of len
.
str
- the characters to be appended.offset
- the index of the first character to append.len
- the number of characters to append.
String
object.public String append(boolean b)
boolean
argument to the string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
b
- a boolean
.
String
.public String append(char c)
char
argument to this string.
The argument is appended to the contents of this string buffer.
The length of this string buffer increases by 1
.
c
- a char
.
String
object.public String append(byte b)
byte
argument to this string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
b
- an byte
.
String
object.public String append(short s)
short
argument to this string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
s
- an short
.
String
object.public String append(int i)
int
argument to this string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
i
- an int
.
String
object.public String append(long l)
long
argument to this string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
l
- a long
.
String
object.public String append(double d)
double
argument to this string.
The argument is converted to a string as if by the method
String.valueOf
, and the characters of that
string are then appended to this string.
d
- a double
.
String
object.public String concat(String str)
If the length of the argument string is 0
, then this
String
object is returned. If the value made reference
to an ANSI string, this reference is not kept. Otherwise, a the value of this
String
object is modified, representing a character
sequence that is the concatenation of the character sequence
represented by this String
object and the character
sequence represented by the argument string. In both case, the String to
concatenate is finalized.
str
- the String
that is concatenated to the end
of this String
.
public char charAt(int index)
0
to length() - 1
. The first character
of the sequence is at index 0
, the next at index
1
, and so on, as for array indexing.
index
- the index of the character.
0
.public String delete(int start, int end)
String
.
The substring begins at the specified start
and extends to
the character at index end - 1
. If
start
is equal to end
, no changes are made.
start
- The beginning index, inclusive.end
- The ending index, exclusive.
public void getChars(int srcBegin, int srcEnd, char_p dst, int dstBegin)
The first character to be copied is at index srcBegin
;
the last character to be copied is at index srcEnd-1
(thus the total number of characters to be copied is
srcEnd-srcBegin
). The characters are copied into the
subarray of dst
starting at index dstBegin
and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
srcBegin
- index of the first character in the string
to copy.srcEnd
- index after the last character in the string
to copy.dst
- the destination array.dstBegin
- the start offset in the destination array.public int indexOf(String str, int fromIndex)
str
- the substring for which to search.fromIndex
- the index from which to start the search.
public int lastIndexOf(String str, int fromIndex)
If no such value of k exists, then -1 is returned.k <= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
str
- the substring to search for.fromIndex
- the index to start the search from.
public boolean regionMatches(int toffset, String other, int ooffset, int len)
A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len.
toffset
- the starting offset of the subregion in this string.other
- the string argument.ooffset
- the starting offset of the subregion in the string
argument.len
- the number of characters to compare.
true
if the specified subregion of this string
exactly matches the specified subregion of the string argument;
false
otherwise.public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent character sequences that are the same, ignoring case if and only if ignoreCase is true. The substring of this String object to be compared begins at index toffset and has length len. The result is false otherwize. The substring of other to be compared begins at index ooffset and has length len.
ignoreCase
- if true
, ignore case when comparing
characters.toffset
- the starting offset of the subregion in this
string.other
- the string argument.ooffset
- the starting offset of the subregion in the string
argument.len
- the number of characters to compare.
true
if the specified subregion of this string
matches the specified subregion of the string argument;
false
otherwise. Whether the matching is exact
or case insensitive depends on the ignoreCase
argument.public String replace(char oldChar, char newChar)
oldChar
in this string with newChar
.
If the character oldChar
does not occur in the
character sequence represented by this String
object,
then a reference to this String
object is returned.
Otherwise, this string object will be modified to
represents a character sequence identical to the character sequence
represented by this String
object, except that every
occurrence of oldChar
is replaced by an occurrence
of newChar
.
oldChar
- the old character.newChar
- the new character.
oldChar
replaced by newChar
.public String replace(String oldStr, String newStr)
oldStr
substring in this string with newStr
.
If the substring oldStr
does not occur in the
character sequence represented by this String
object,
then a reference to this String
object is returned.
Otherwise, this string object will be modified to
represents a character sequence identical to the character sequence
represented by this String
object, except that every
occurrence of oldStr
substring is replaced by an occurrence
of newStr
.
oldStr
replaced by newStr
.public boolean startsWith(String prefix, int toffset)
prefix
- the prefix.toffset
- where to begin looking in the string.
true
if the character sequence represented by the
argument is a prefix of the substring of this object starting
at index toffset
; false
otherwise.public String substring(int beginIndex, int endIndex)
beginIndex
and
extends to the character at index endIndex - 1
.
Thus the length of the substring is endIndex-beginIndex
.
beginIndex
- the beginning index, inclusive.endIndex
- the ending index, exclusive.
public String toLowerCase()
String
to lower
case.
String
, converted to lowercase.public String toString()
toString
in class Object
public String toUpperCase()
String
to upper
case.
String
, converted to uppercase.public String trim()
public boolean endsWith(String suffix)
suffix
- the suffix.
true
if the character sequence represented by the
argument is a suffix of the character sequence represented by
this object; false
otherwise. Note that the
result will be true
if the argument is the
empty string or is equal to this String
object.public boolean equals(Object object)
true
if and only if the argument is not
null
and is a String
object that represents
the same sequence of characters as this object.
equals
in class Object
object
- the reference object with which to compare.
true
if the String
are equal;
false
otherwise.public boolean equalsIgnoreCase(String anotherString)
String
to another String
,
ignoring case considerations. Two strings are considered equal
ignoring case if they are of the same length, and corresponding
characters in the two strings are equal ignoring case.
anotherString
- the String
to compare this
String
against.
true
if the argument is not null
and the String
s are equal,
ignoring case; false
otherwise.public void finalize()
finalize
in class Object
public short compareTo(String anotherString)
String
object is compared lexicographically to the
character sequence represented by the argument string. The result is
a negative integer if this String
object
lexicographically precedes the argument string. The result is a
positive integer if this String
object lexicographically
follows the argument string. The result is zero if the strings
are equal; compareTo
returns 0
exactly when
the equals(Object)
method would return true
.
This is the definition of lexicographic ordering. If two strings are
different, then either they have different characters at some index
that is a valid index for both strings, or their lengths are different,
or both. If they have different characters at one or more index
positions, let k be the smallest such index; then the string
whose character at position k has the smaller value, as
determined by using the < operator, lexicographically precedes the
other string. In this case, compareTo
returns the
difference of the two character values at position k
in
the two string -- that is, the value:
this.charAt(k)-anotherString.charAt(k)
anotherString
- the String
to be compared.
0
if the argument string is equal to
this string; a value less than 0
if this string
is lexicographically less than the string argument; and a
value greater than 0
if this string is
lexicographically greater than the string argument.public int length()
public short strcmp(char_p ansiString)
String
object is compared lexicographically to the
character sequence represented by the argument ANSI string. The result is
a negative integer if this String
object
lexicographically precedes the argument ANSI string. The result is a
positive integer if this String
object lexicographically
follows the argument string. The result is zero if the strings
are equal.
This is the definition of lexicographic ordering. If two strings are
different, then either they have different characters at some index
that is a valid index for both strings, or their lengths are different,
or both. If they have different characters at one or more index
positions, let k be the smallest such index; then the string
whose character at position k has the smaller value, as
determined by using the < operator, lexicographically precedes the
other string. In this case, strcmp
returns the
difference of the two character values at position k
in
the two string -- that is, the value:
this.charAt(k)-ansiString[k]
ansiString
- the ANSI String
to be compared.
0
if the argument ANSI string is equal to
this string; a value less than 0
if this string
is lexicographically less than the ANSI string argument; and a
value greater than 0
if this string is
lexicographically greater than the ANSI string argument.public char_p toVat()
public static String valueOf(char c)
char
argument.
c
- an char
.
char
argument.public static String valueOf(boolean b)
boolean
argument.
b
- a boolean
.
true
, a string equal to
"true"
is returned; otherwise, a string equal to
"false"
is returned.public static String valueOf(byte b)
byte
argument.
b
- a byte
.
byte
argument.public static String valueOf(UByte b)
ubyte
argument.
b
- a ubyte
.
byte
argument.public static String valueOf(short s)
short
argument.
s
- an short
.
short
argument.public static String valueOf(UShort s)
ushort
argument.
s
- an ushort
.
ushort
argument.public static String valueOf(int i)
int
argument.
i
- an int
.
int
argument.public static String valueOf(UInteger i)
uint
argument.
i
- an uint
.
uint
argument.public static String valueOf(long l)
long
argument.
l
- an long
.
long
argument.public static String valueOf(ULong l)
ulong
argument.
l
- an ulong
.
ulong
argument.public static String valueOf(double d)
double
argument.
d
- an double
.
double
argument.public static String valueOf(char_p ansiString)
public static String valueOf(char_p data, int length)
char
array
argument. The contents of the character array are copied; subsequent
modification of the character array does not affect the newly
created string.
data
- a char
array.length
- the length of the char
array.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |