String Class Reference

List of all members.

Detailed Description

The JUCE String class!

Using a reference-counted internal representation, these strings are fast and efficient, and there are methods to do just about any operation you'll ever dream of.

See also:
StringArray, StringPairArray


Public Member Functions

 String () throw ()
 Creates an empty string.
 String (const String &other) throw ()
 Creates a copy of another string.
 String (const char *const text) throw ()
 Creates a string from a zero-terminated text string.
 String (const char *const text, const int maxChars) throw ()
 Creates a string from an string of characters.
 String (const juce_wchar *const unicodeText) throw ()
 Creates a string from a zero-terminated unicode text string.
 String (const juce_wchar *const unicodeText, const int maxChars) throw ()
 Creates a string from a unicode text string.
 ~String () throw ()
 Destructor.
int hashCode () const throw ()
 Generates a probably-unique 32-bit hashcode from this string.
int64 hashCode64 () const throw ()
 Generates a probably-unique 64-bit hashcode from this string.
int length () const throw ()
 Returns the number of characters in the string.
const Stringoperator= (const tchar *const other) throw ()
 Replaces this string's contents with another string.
const Stringoperator= (const String &other) throw ()
 Replaces this string's contents with another string.
const Stringoperator+= (const tchar *const textToAppend) throw ()
 Appends another string at the end of this one.
const Stringoperator+= (const String &stringToAppend) throw ()
 Appends another string at the end of this one.
const Stringoperator+= (const char characterToAppend) throw ()
 Appends a character at the end of this string.
const Stringoperator+= (const juce_wchar characterToAppend) throw ()
 Appends a character at the end of this string.
void append (const tchar *const textToAppend, const int maxCharsToTake) throw ()
 Appends a string at the end of this one.
const String operator+ (const String &stringToAppend) const throw ()
 Appends a string at the end of this one.
const String operator+ (const tchar *const textToAppend) const throw ()
 Appends a string at the end of this one.
const String operator+ (const tchar characterToAppend) const throw ()
 Appends a character at the end of this one.
Stringoperator<< (const char n) throw ()
 Appends a character at the end of this string.
Stringoperator<< (const juce_wchar n) throw ()
 Appends a character at the end of this string.
Stringoperator<< (const char *const text) throw ()
 Appends another string at the end of this one.
Stringoperator<< (const juce_wchar *const text) throw ()
 Appends another string at the end of this one.
Stringoperator<< (const String &text) throw ()
 Appends another string at the end of this one.
Stringoperator<< (const short number) throw ()
 Appends a decimal number at the end of this string.
Stringoperator<< (const int number) throw ()
 Appends a decimal number at the end of this string.
Stringoperator<< (const unsigned int number) throw ()
 Appends a decimal number at the end of this string.
Stringoperator<< (const float number) throw ()
 Appends a decimal number at the end of this string.
Stringoperator<< (const double number) throw ()
 Appends a decimal number at the end of this string.
bool isEmpty () const throw ()
 Returns true if the string contains no characters.
bool isNotEmpty () const throw ()
 Returns true if the string contains at least one character.
bool operator== (const String &other) const throw ()
 Case-sensitive comparison with another string.
bool operator== (const tchar *const other) const throw ()
 Case-sensitive comparison with another string.
bool operator!= (const String &other) const throw ()
 Case-sensitive comparison with another string.
bool operator!= (const tchar *const other) const throw ()
 Case-sensitive comparison with another string.
bool equalsIgnoreCase (const String &other) const throw ()
 Case-insensitive comparison with another string.
bool equalsIgnoreCase (const tchar *const other) const throw ()
 Case-insensitive comparison with another string.
bool operator> (const String &other) const throw ()
 Case-sensitive comparison with another string.
bool operator< (const tchar *const other) const throw ()
 Case-sensitive comparison with another string.
bool operator>= (const String &other) const throw ()
 Case-sensitive comparison with another string.
bool operator<= (const tchar *const other) const throw ()
 Case-sensitive comparison with another string.
int compare (const tchar *const other) const throw ()
 Case-sensitive comparison with another string.
int compareIgnoreCase (const tchar *const other) const throw ()
 Case-insensitive comparison with another string.
int compareLexicographically (const tchar *const other) const throw ()
 Lexicographic comparison with another string.
bool startsWith (const tchar *const text) const throw ()
 Tests whether the string begins with another string.
bool startsWithChar (const tchar character) const throw ()
 Tests whether the string begins with a particular character.
bool startsWithIgnoreCase (const tchar *const text) const throw ()
 Tests whether the string begins with another string.
bool endsWith (const tchar *const text) const throw ()
 Tests whether the string ends with another string.
bool endsWithChar (const tchar character) const throw ()
 Tests whether the string ends with a particular character.
bool endsWithIgnoreCase (const tchar *const text) const throw ()
 Tests whether the string ends with another string.
bool contains (const tchar *const text) const throw ()
 Tests whether the string contains another substring.
bool containsChar (const tchar character) const throw ()
 Tests whether the string contains a particular character.
bool containsIgnoreCase (const tchar *const text) const throw ()
 Tests whether the string contains another substring.
bool containsWholeWord (const tchar *const wordToLookFor) const throw ()
 Tests whether the string contains another substring as a distict word.
bool containsWholeWordIgnoreCase (const tchar *const wordToLookFor) const throw ()
 Tests whether the string contains another substring as a distict word.
int indexOfWholeWord (const tchar *const wordToLookFor) const throw ()
 Finds an instance of another substring if it exists as a distict word.
int indexOfWholeWordIgnoreCase (const tchar *const wordToLookFor) const throw ()
 Finds an instance of another substring if it exists as a distict word.
bool containsAnyOf (const tchar *const charactersItMightContain) const throw ()
 Looks for any of a set of characters in the string.
bool containsOnly (const tchar *const charactersItMightContain) const throw ()
 Looks for a set of characters in the string.
bool matchesWildcard (const tchar *wildcard, const bool ignoreCase) const throw ()
 Returns true if the string matches this simple wildcard expression.
int indexOfChar (const tchar characterToLookFor) const throw ()
 Searches for a character inside this string.
int indexOfChar (const int startIndex, const tchar characterToLookFor) const throw ()
 Searches for a character inside this string.
int indexOfAnyOf (const tchar *const charactersToLookFor, const int startIndex=0, const bool ignoreCase=false) const throw ()
 Returns the index of the first character that matches one of the characters passed-in to this method.
int indexOf (const tchar *const text) const throw ()
 Searches for a substring within this string.
int indexOf (const int startIndex, const tchar *const textToLookFor) const throw ()
 Searches for a substring within this string.
int indexOfIgnoreCase (const tchar *const textToLookFor) const throw ()
 Searches for a substring within this string.
int indexOfIgnoreCase (const int startIndex, const tchar *const textToLookFor) const throw ()
 Searches for a substring within this string.
int lastIndexOfChar (const tchar character) const throw ()
 Searches for a character inside this string (working backwards from the end of the string).
int lastIndexOf (const tchar *const textToLookFor) const throw ()
 Searches for a substring inside this string (working backwards from the end of the string).
int lastIndexOfIgnoreCase (const tchar *const textToLookFor) const throw ()
 Searches for a substring inside this string (working backwards from the end of the string).
int lastIndexOfAnyOf (const tchar *const charactersToLookFor, const bool ignoreCase=false) const throw ()
 Returns the index of the last character in this string that matches one of the characters passed-in to this method.
const tcharoperator[] (const int index) const throw ()
 Returns the character at this index in the string.
tcharoperator[] (const int index) throw ()
 Returns a character from the string such that it can also be altered.
tchar getLastCharacter () const throw ()
 Returns the final character of the string.
const String substring (int startIndex, int endIndex) const throw ()
 Returns a subsection of the string.
const String substring (const int startIndex) const throw ()
 Returns a section of the string, starting from a given position.
const String dropLastCharacters (const int numberToDrop) const throw ()
 Returns a version of this string with a number of characters removed from the end.
const String fromFirstOccurrenceOf (const tchar *const substringToStartFrom, const bool includeSubStringInResult, const bool ignoreCase) const throw ()
 Returns a section of the string starting from a given substring.
const String fromLastOccurrenceOf (const tchar *const substringToFind, const bool includeSubStringInResult, const bool ignoreCase) const throw ()
 Returns a section of the string starting from the last occurrence of a given substring.
const String upToFirstOccurrenceOf (const tchar *const substringToEndWith, const bool includeSubStringInResult, const bool ignoreCase) const throw ()
 Returns the start of this string, up to the first occurrence of a substring.
const String upToLastOccurrenceOf (const tchar *substringToFind, const bool includeSubStringInResult, const bool ignoreCase) const throw ()
 Returns the start of this string, up to the last occurrence of a substring.
const String trim () const throw ()
 Returns a copy of this string with any whitespace characters removed from the start and end.
const String trimStart () const throw ()
 Returns a copy of this string with any whitespace characters removed from the start.
const String trimEnd () const throw ()
 Returns a copy of this string with any whitespace characters removed from the end.
const String toUpperCase () const throw ()
 Returns an upper-case version of this string.
const String toLowerCase () const throw ()
 Returns an lower-case version of this string.
const String replaceSection (int startIndex, int numCharactersToReplace, const tchar *const stringToInsert) const throw ()
 Replaces a sub-section of the string with another string.
const String replace (const tchar *const stringToReplace, const tchar *const stringToInsertInstead, const bool ignoreCase=false) const throw ()
 Replaces all occurrences of a substring with another string.
const String replaceCharacter (const tchar characterToReplace, const tchar characterToInsertInstead) const throw ()
 Returns a string with all occurrences of a character replaced with a different one.
const String replaceCharacters (const String &charactersToReplace, const tchar *const charactersToInsertInstead) const throw ()
 Replaces a set of characters with another set.
const String retainCharacters (const tchar *const charactersToRetain) const throw ()
 Returns a version of this string that only retains a fixed set of characters.
const String removeCharacters (const tchar *const charactersToRemove) const throw ()
 Returns a version of this string with a set of characters removed.
const String initialSectionContainingOnly (const tchar *const permittedCharacters) const throw ()
 Returns a section from the start of the string that only contains a certain set of characters.
const String initialSectionNotContaining (const tchar *const charactersToStopAt) const throw ()
 Returns a section from the start of the string that only contains a certain set of characters.
bool isQuotedString () const throw ()
 Checks whether the string might be in quotation marks.
const String unquoted () const throw ()
 Removes quotation marks from around the string, (if there are any).
const String quoted (const tchar quoteCharacter=JUCE_T('"')) const throw ()
 Adds quotation marks around a string.
void printf (const tchar *const format,...) throw ()
 Writes text into this string, using printf style-arguments.
void vprintf (const tchar *const format, va_list &args) throw ()
 Writes text into this string, using a printf style, but taking a va_list argument.
 String (const int decimalInteger) throw ()
 Creates a string containing this signed 32-bit integer as a decimal number.
 String (const unsigned int decimalInteger) throw ()
 Creates a string containing this unsigned 32-bit integer as a decimal number.
 String (const short decimalInteger) throw ()
 Creates a string containing this signed 16-bit integer as a decimal number.
 String (const unsigned short decimalInteger) throw ()
 Creates a string containing this unsigned 16-bit integer as a decimal number.
 String (const int64 largeIntegerValue) throw ()
 Creates a string containing this signed 64-bit integer as a decimal number.
 String (const uint64 largeIntegerValue) throw ()
 Creates a string containing this unsigned 64-bit integer as a decimal number.
 String (const float floatValue, const int numberOfDecimalPlaces=0) throw ()
 Creates a string representing this floating-point number.
 String (const double doubleValue, const int numberOfDecimalPlaces=0) throw ()
 Creates a string representing this floating-point number.
int getIntValue () const throw ()
 Parses this string to find its numerical value (up to 32 bits in size).
int64 getLargeIntValue () const throw ()
 Parses this string to find its numerical value (up to 64 bits in size).
int getTrailingIntValue () const throw ()
 Parses a decimal number from the end of the string.
float getFloatValue () const throw ()
 Parses this string as a floating point number.
double getDoubleValue () const throw ()
 Parses this string as a floating point number.
int getHexValue32 () const throw ()
 Parses the string as a hexadecimal number.
int64 getHexValue64 () const throw ()
 Parses the string as a hexadecimal number.
 operator const char * () const throw ()
 Returns a version of this string using the default 8-bit system encoding.
 operator const juce_wchar * () const throw ()
 Returns a unicode version of this string.
void copyToBuffer (char *const destBuffer, const int maxCharsToCopy) const throw ()
 Copies the string to a buffer.
void copyToBuffer (juce_wchar *const destBuffer, const int maxCharsToCopy) const throw ()
 Copies the string to a unicode buffer.
int copyToUTF8 (uint8 *const destBuffer) const throw ()
 Copies the string to a buffer as UTF-8 characters.
const char * toUTF8 () const throw ()
 Returns a pointer to a UTF-8 version of this string.
void preallocateStorage (const int numCharsNeeded) throw ()
 Increases the string's internally allocated storage.

Static Public Member Functions

static const String charToString (const tchar character) throw ()
 Creates a string from a single character.
static const String formatted (const tchar *const format,...) throw ()
 Returns a string, created using arguments in the style of printf.
static const String repeatedString (const tchar *const stringToRepeat, int numberOfTimesToRepeat) throw ()
 Creates a string which is a version of a string repeated and joined together.
static const String createStringFromData (const void *const data, const int size) throw ()
 Creates a string from data in an unknown format.
static const String toHexString (const int number) throw ()
 Creates a string representing this 32-bit value in hexadecimal.
static const String toHexString (const int64 number) throw ()
 Creates a string representing this 64-bit value in hexadecimal.
static const String toHexString (const short number) throw ()
 Creates a string representing this 16-bit value in hexadecimal.
static const String toHexString (const unsigned char *data, const int size, const int groupSize=1) throw ()
 Creates a string containing a hex dump of a block of binary data.
static const String fromUTF8 (const uint8 *const utf8buffer, int bufferSizeBytes=-1) throw ()
 Creates a String from a UTF-8 encoded buffer.

Static Public Attributes

static const String empty
 This is an empty string that can be used whenever one is needed.


Constructor & Destructor Documentation

String::String  )  throw ()
 

Creates an empty string.

See also:
empty

String::String const String other  )  throw ()
 

Creates a copy of another string.

String::String const char *const   text  )  throw ()
 

Creates a string from a zero-terminated text string.

The string is assumed to be stored in the default system encoding.

String::String const char *const   text,
const int  maxChars
throw ()
 

Creates a string from an string of characters.

This will use up the the first maxChars characters of the string (or less if the string is actually shorter)

String::String const juce_wchar *const   unicodeText  )  throw ()
 

Creates a string from a zero-terminated unicode text string.

String::String const juce_wchar *const   unicodeText,
const int  maxChars
throw ()
 

Creates a string from a unicode text string.

This will use up the the first maxChars characters of the string (or less if the string is actually shorter)

String::~String  )  throw ()
 

Destructor.

String::String const int  decimalInteger  )  throw () [explicit]
 

Creates a string containing this signed 32-bit integer as a decimal number.

See also:
getIntValue, getFloatValue, getDoubleValue, toHexString

String::String const unsigned int  decimalInteger  )  throw () [explicit]
 

Creates a string containing this unsigned 32-bit integer as a decimal number.

See also:
getIntValue, getFloatValue, getDoubleValue, toHexString

String::String const short  decimalInteger  )  throw () [explicit]
 

Creates a string containing this signed 16-bit integer as a decimal number.

See also:
getIntValue, getFloatValue, getDoubleValue, toHexString

String::String const unsigned short  decimalInteger  )  throw () [explicit]
 

Creates a string containing this unsigned 16-bit integer as a decimal number.

See also:
getIntValue, getFloatValue, getDoubleValue, toHexString

String::String const int64  largeIntegerValue  )  throw () [explicit]
 

Creates a string containing this signed 64-bit integer as a decimal number.

See also:
getLargeIntValue, getFloatValue, getDoubleValue, toHexString

String::String const uint64  largeIntegerValue  )  throw () [explicit]
 

Creates a string containing this unsigned 64-bit integer as a decimal number.

See also:
getLargeIntValue, getFloatValue, getDoubleValue, toHexString

String::String const float  floatValue,
const int  numberOfDecimalPlaces = 0
throw () [explicit]
 

Creates a string representing this floating-point number.

Parameters:
floatValue the value to convert to a string
numberOfDecimalPlaces if this is > 0, it will format the number using that many decimal places, and will not use exponent notation. If 0 or less, it will use exponent notation if necessary.
See also:
getDoubleValue, getIntValue

String::String const double  doubleValue,
const int  numberOfDecimalPlaces = 0
throw () [explicit]
 

Creates a string representing this floating-point number.

Parameters:
doubleValue the value to convert to a string
numberOfDecimalPlaces if this is > 0, it will format the number using that many decimal places, and will not use exponent notation. If 0 or less, it will use exponent notation if necessary.
See also:
getFloatValue, getIntValue


Member Function Documentation

static const String String::charToString const tchar  character  )  throw () [static]
 

Creates a string from a single character.

int String::hashCode  )  const throw ()
 

Generates a probably-unique 32-bit hashcode from this string.

int64 String::hashCode64  )  const throw ()
 

Generates a probably-unique 64-bit hashcode from this string.

int String::length  )  const throw ()
 

Returns the number of characters in the string.

const String& String::operator= const tchar *const   other  )  throw ()
 

Replaces this string's contents with another string.

const String& String::operator= const String other  )  throw ()
 

Replaces this string's contents with another string.

const String& String::operator+= const tchar *const   textToAppend  )  throw ()
 

Appends another string at the end of this one.

const String& String::operator+= const String stringToAppend  )  throw ()
 

Appends another string at the end of this one.

const String& String::operator+= const char  characterToAppend  )  throw ()
 

Appends a character at the end of this string.

const String& String::operator+= const juce_wchar  characterToAppend  )  throw ()
 

Appends a character at the end of this string.

void String::append const tchar *const   textToAppend,
const int  maxCharsToTake
throw ()
 

Appends a string at the end of this one.

Parameters:
textToAppend the string to add
maxCharsToTake the maximum number of characters to take from the string passed in

const String String::operator+ const String stringToAppend  )  const throw ()
 

Appends a string at the end of this one.

Returns:
the concatenated string

const String String::operator+ const tchar *const   textToAppend  )  const throw ()
 

Appends a string at the end of this one.

Returns:
the concatenated string

const String String::operator+ const tchar  characterToAppend  )  const throw ()
 

Appends a character at the end of this one.

Returns:
the concatenated string

String& String::operator<< const char  n  )  throw ()
 

Appends a character at the end of this string.

String& String::operator<< const juce_wchar  n  )  throw ()
 

Appends a character at the end of this string.

String& String::operator<< const char *const   text  )  throw ()
 

Appends another string at the end of this one.

String& String::operator<< const juce_wchar *const   text  )  throw ()
 

Appends another string at the end of this one.

String& String::operator<< const String text  )  throw ()
 

Appends another string at the end of this one.

String& String::operator<< const short  number  )  throw ()
 

Appends a decimal number at the end of this string.

String& String::operator<< const int  number  )  throw ()
 

Appends a decimal number at the end of this string.

String& String::operator<< const unsigned int  number  )  throw ()
 

Appends a decimal number at the end of this string.

String& String::operator<< const float  number  )  throw ()
 

Appends a decimal number at the end of this string.

String& String::operator<< const double  number  )  throw ()
 

Appends a decimal number at the end of this string.

bool String::isEmpty  )  const throw ()
 

Returns true if the string contains no characters.

Note that there's also an isNotEmpty() method to help write readable code.

bool String::isNotEmpty  )  const throw ()
 

Returns true if the string contains at least one character.

Note that there's also an isEmpty() method to help write readable code.

bool String::operator== const String other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator== const tchar *const   other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator!= const String other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator!= const tchar *const   other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::equalsIgnoreCase const String other  )  const throw ()
 

Case-insensitive comparison with another string.

bool String::equalsIgnoreCase const tchar *const   other  )  const throw ()
 

Case-insensitive comparison with another string.

bool String::operator> const String other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator< const tchar *const   other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator>= const String other  )  const throw ()
 

Case-sensitive comparison with another string.

bool String::operator<= const tchar *const   other  )  const throw ()
 

Case-sensitive comparison with another string.