This page describes the current methods in the String class at this point in time. It
is possible that additional Java-defined methods might be added later, such as Thread
support methods. It is also possible that extensions might be added, if needed.
Constructors aka CTORs
String Potato; - Default CTOR
String Potato = "POTATO"; - Literal CTOR
String Potato("POTATO"); - Literal CTOR
String Spud = Potato; - Copy CTOR
Spud = Potato; // Assignment operator - String to String
Spud = "Potato"; // Assignment operator - Literal to String
Tubers = Potato + Spud; // Addition operator - String + String
Tubers = Potato + "SPUD" // Addition operator - String + Literal ***
Team += "TeamCaptain" // Addition assignment operator - String += Literal
Team += TeamCaptain // Addition assignment operator - String += String
The charAt() method works, but it returns a (wchar_t) data type, which needs to
be cast to a (char) data type when used in a cout statement. I can probably fix this
so it works smoothly in what will be the C++ version of System.out.println(). For
the code snippet:
String veggie = "POTATO";
cout << "veggie.charAt(0) = '" << (char) veggie.charAt(0) << "'.\n";
veggie.charAt(0) = 'P'.
The clone method will be implemented if it is needed.
The concat method isn't needed. Map to "+" instead. For example, instead of
Succotash = Beans.concat("Corn");
Sandwich = PeanutButter.concat(Jelly);
Succotash = Beans + "Corn";
Sandwich = PeanutButter + Jelly;
The equals method will be implemented soon. Two objects are considered to be
equal if they both refer to the same memory location allocated to hold the object data.
The getClass method will be implemented if it is needed. There is no Class class
The hashCode method seems to work. It returns an unsigned long data type. It does
NOT return the same values as does the real Java String.hashCode() method.
The length method works as expected and returns the number of 16-bit characters
in the String. Note that our Strings do not contain terminating characters, as one
would find in a "normal" C string. For example:
The code snippet:
String veggie = "SPUD";
cout << veggie.length;
The substr is being developed, if i figure how to return a String& that works.
Nickname = William.substr(0,4); // Nickname is now "Will"
The toString method is being developed along with the String class.