(I once had a similar string class for VMS, internally formatted as a string descriptor. It worked great; I don't know why the Big Guys don't supply such classes with their compilers.)
You can browse the functions and operators below. And you can grab the code (which is mostly self-explanatory):
| Operators | ||
|---|---|---|
| Operator | Description | Example Usage |
| = | assignment | myString = "wowzers"; myString = myCharArray; |
| const char* | conversion | expectsCharArry(myString); |
| == != > < >= <= | comparison | if (myString1 < myString2)
if (myString == "wowzers") while (myString != "") |
| [] | array-like indexing | firstChar = myString[0]; |
| () | same as Substr | firstThree = myString(0,2) |
| + | concatenation | myString = myStr1 + myStr2;
myString = (String)"this" + "that"; |
| += | extension | myString += "moreStuff"; myString += myOtherStr; |
| * | repetition | threeWows = (String)"wow" * 3; |
| *= | self-repetition | bearsRepeating *= 2; |
| << | stream output | cout << myString; |
| >> | stream input | cin >> oneWord; |
| Member Functions | ||
|---|---|---|
| Functions | Description | Example Usage |
| Length() | length of string | myWowStr.Length() == 3 |
| Index(s) | location of substring | pos = myString.Index("sub"); |
| Element(i,c) | element extraction | secondWord = myString.Element(1);
field3 = myString.Element(2,'\t'); |
| Substr(i,j) | substring extraction | cde = myAlphabet.Substr(2,4); |
| Left(i) | leftmost chars | abcd = myAlphabet.Left(4); |
| Right(i) | rightmost chars | xyz = myAlphabet.Right(3); |
| Trim() | remove leading/trailing blanks | if (myCmd.Trim() == "run") |
| Friend Functions | ||
|---|---|---|
| Functions | Description | Example Usage |
| IntValue(s) | convert to int | if (IntValue(myString) == 42) |
| Plural(s) | make plural | cout << Plural(myString); |
| Uppercase(s) | make all CAPS | if (Uppercase(myString) == "WOW") |
http://www-ncmir.ucsd.edu/~jstrout/classlib/String.html