Loading...
Searching...
No Matches
Public Member Functions | List of all members
BString Class Reference

String class supporting common string operations. More...

#include <String.h>

Public Member Functions

 BString ()
 Creates an empty BString.
 
 BString (BString &&string) noexcept
 Move the data from the string to this object.
 
 BString (const BString &string)
 Creates and initializes a BString as a copy of another string.
 
 BString (const char *string)
 Creates and initializes a BString from string.
 
 BString (const char *string, int32 maxLength)
 Creates and initializes a BString from a string up to maxLength characters.
 
 ~BString ()
 Free all resources associated with the object.
 
Assignment

To assign a string to the object, thus overriding the previous string that was stored, there are different methods to use. Use one of the overloaded Adopt() methods to take over data from another object. Use one of the assignment operators to copy data from another object, or use one of the SetTo() methods for more advanced copying.

BStringoperator= (const BString &string)
 Re-initialize the object to a copy of the data of a BString.
 
BStringoperator= (const char *string)
 Re-initialize the BString to a copy of the data of a string.
 
BStringoperator= (char c)
 Re-initialize the BString to a character.
 
BStringoperator= (BString &&string) noexcept
 Move the contents of string to this BString object.
 
BStringSetTo (const char *string)
 Re-initialize the BString to a copy of the data of a string.
 
BStringSetTo (const char *string, int32 maxLength)
 Re-initialize the BString to a copy of the data of a string.
 
BStringSetTo (const BString &string)
 Re-initialize the BString to a copy of the data of a BString.
 
BStringAdopt (BString &from)
 Adopt the data of the given BString object.
 
BStringSetTo (const BString &string, int32 maxLength)
 Re-initialize the string to a copy of the given BString object.
 
BStringAdopt (BString &from, int32 maxLength)
 Adopt the data of the given BString object up to maxLength characters.
 
BStringSetTo (char c, int32 count)
 Re-initialize the object to a string composed of a character you specify.
 
BStringSetToChars (const char *string, int32 charCount)
 UTF-8 aware version of SetTo(const char*, int32)
 
BStringSetToChars (const BString &string, int32 charCount)
 UTF-8 aware version of SetTo(BString&, int32)
 
BStringAdoptChars (BString &from, int32 charCount)
 UTF-8 aware version of Adopt(BString&, int32)
 
BStringSetToFormat (const char *format,...)
 Sets the string to a formatted string ala sprintf().
 
BStringSetToFormatVarArgs (const char *format, va_list args)
 Sets the string to a formatted string ala sprintf().
 
int ScanWithFormat (const char *format,...)
 Parse a formatted string and save elements to variables ala scanf().
 
int ScanWithFormatVarArgs (const char *format, va_list args)
 Parse a formatted string and save elements to variables ala scanf().
 
Substring Copying
BStringCopyInto (BString &into, int32 fromOffset, int32 length) const
 Copy the object's data (or part of it) into another BString.
 
void CopyInto (char *into, int32 fromOffset, int32 length) const
 Copy the BString data (or part of it) into the supplied buffer.
 
BStringCopyCharsInto (BString &into, int32 fromCharOffset, int32 charCount) const
 UTF-8 aware version of CopyInto(BString&, int32, int32) const.
 
bool CopyCharsInto (char *into, int32 *intoLength, int32 fromCharOffset, int32 charCount) const
 UTF-8 aware version of CopyInto(char*, int32, int32) const.
 
bool Split (const char *separator, bool noEmptyStrings, BStringList &_list) const
 Split the string by the separator chars into _list.
 
Appending
BStringoperator+= (const BString &string)
 Append the given string to the end of the BString.
 
BStringoperator+= (const char *string)
 Append the given string to the end of the BString.
 
BStringoperator+= (char c)
 Append the given character to the end of the BString.
 
BStringAppend (const BString &string)
 Append the given string to the end of the BString.
 
BStringAppend (const char *string)
 Append the string data to the end of the BString.
 
BStringAppend (const BString &string, int32 length)
 Append a part of the given string to the end of the BString.
 
BStringAppend (const char *string, int32 length)
 Append a part of the given string to end of the BString.
 
BStringAppend (char c, int32 count)
 Append the given character repeatedly to the end of the BString.
 
BStringAppendChars (const BString &string, int32 charCount)
 UTF-8 aware version of Append(const BString&, int32).
 
BStringAppendChars (const char *string, int32 charCount)
 UTF-8 aware version of Append(const char*, int32).
 
Prepending
BStringPrepend (const char *string)
 Prepend the given string to the beginning of the BString.
 
BStringPrepend (const BString &string)
 Prepend the given BString to the beginning of the BString.
 
BStringPrepend (const char *string, int32 length)
 Prepend the given string to the beginning of the BString.
 
BStringPrepend (const BString &string, int32 length)
 Prepend the given BString to the beginning of the BString.
 
BStringPrepend (char c, int32 count)
 Prepend the given character count times to the beginning of the BString.
 
BStringPrependChars (const char *string, int32 charCount)
 UTF-8 aware version of Prepend(const char*, int32).
 
BStringPrependChars (const BString &string, int32 charCount)
 UTF-8 aware version of Prepend(const BString&, int32).
 
Inserting
BStringInsert (const char *string, int32 position)
 Inserts the given string at the given position into the BString data.
 
BStringInsert (const char *string, int32 length, int32 position)
 Inserts the given string at the given position into the BString data.
 
BStringInsert (const char *string, int32 fromOffset, int32 length, int32 position)
 Inserts the given string at the given position into the BString data.
 
BStringInsert (const BString &string, int32 position)
 Inserts the given BString at the given position into the BString data.
 
BStringInsert (const BString &string, int32 length, int32 position)
 Inserts the given BString at the given position into the BString data.
 
BStringInsert (const BString &string, int32 fromOffset, int32 length, int32 position)
 Inserts the given string at the given position into the BString data.
 
BStringInsert (char c, int32 count, int32 position)
 Inserts the given character repeatedly at the given position into the BString data.
 
BStringInsertChars (const char *string, int32 charPosition)
 UTF-8 aware version of Insert(const char*, int32).
 
BStringInsertChars (const char *string, int32 charCount, int32 charPosition)
 UTF-8 aware version of Insert(const char*, int32, int32).
 
BStringInsertChars (const char *string, int32 fromCharOffset, int32 charCount, int32 charPosition)
 UTF-8 aware version of Insert(const char*, int32, int32, int32).
 
BStringInsertChars (const BString &string, int32 charPosition)
 UTF-8 aware version of Insert(const BString&, int32).
 
BStringInsertChars (const BString &string, int32 charCount, int32 charPosition)
 UTF-8 aware version of Insert(const BString&, int32, int32).
 
BStringInsertChars (const BString &string, int32 fromCharOffset, int32 charCount, int32 charPosition)
 UTF-8 aware version of Insert(const BString&, int32, int32, int32).
 
Removing
BStringTruncate (int32 newLength, bool lazy=true)
 Truncate the string to the new length.
 
BStringTruncateChars (int32 newCharCount, bool lazy=true)
 UTF-8 aware version of Truncate(int32, bool).
 
BStringRemove (int32 from, int32 length)
 Remove some bytes, starting at the given offset.
 
BStringRemoveChars (int32 fromCharOffset, int32 charCount)
 UTF-8 aware version of Remove(int32, int32).
 
BStringRemoveFirst (const BString &string)
 Remove the first occurrence of the given BString.
 
BStringRemoveLast (const BString &string)
 Remove the last occurrence of the given BString.
 
BStringRemoveAll (const BString &string)
 Remove all occurrences of the given BString.
 
BStringRemoveFirst (const char *string)
 Remove the first occurrence of the given string.
 
BStringRemoveLast (const char *string)
 Remove the last occurrence of the given string.
 
BStringRemoveAll (const char *string)
 Remove all occurrences of the given string.
 
BStringRemoveSet (const char *setOfBytesToRemove)
 Remove all the characters specified.
 
BStringRemoveCharsSet (const char *setOfCharsToRemove)
 UTF-8 aware version of RemoveSet(const char*).
 
BStringMoveInto (BString &into, int32 from, int32 length)
 Move the BString data (or part of it) into another BString.
 
void MoveInto (char *into, int32 from, int32 length)
 Move the BString data (or part of it) into the given buffer.
 
BStringMoveCharsInto (BString &into, int32 fromCharOffset, int32 charCount)
 UTF-8 aware version of MoveInto(BString&, int32, int32)
 
bool MoveCharsInto (char *into, int32 *intoLength, int32 fromCharOffset, int32 charCount)
 UTF-8 aware version of MoveInto(char*, int32*, int32, int32).
 
BStringTrim ()
 Removes spaces from the beginning and end of the string.
 
Comparison

There are two different comparison methods. First of all there is the whole range of operators that return a boolean value, secondly there are methods that return an integer value, both case sensitive and case insensitive.

There are also global comparison operators and global compare functions. You might need these in case you have a sort routine that takes a generic comparison function, such as BList::SortItems(). See the String.h documentation file to see the specifics, though basically there are the same as implemented in this class.

bool operator< (const BString &string) const
 Lexicographically compare if this BString is less than the given string.
 
bool operator<= (const BString &string) const
 Lexicographically compare if this BString is less than or equal to the given string.
 
bool operator== (const BString &string) const
 Lexicographically compare if this BString is equal to the given string.
 
bool operator>= (const BString &string) const
 Lexicographically compare if this BString is greater than or equal to the given string.
 
bool operator> (const BString &string) const
 Lexicographically compare if this BString is greater than the given string.
 
bool operator!= (const BString &string) const
 Lexicographically compare if this BString is not equal to the given string.
 
bool operator< (const char *string) const
 Lexicographically compare if this BString is less than the given string.
 
bool operator<= (const char *string) const
 Lexicographically compare if this BString is less than or equal to the given string.
 
bool operator== (const char *string) const
 Lexicographically compare if this BString is equal to the given string.
 
bool operator>= (const char *string) const
 Lexicographically compare if this string is more than or equal to a given string.
 
bool operator> (const char *string) const
 Lexicographically compare if this string is more than a given string.
 
bool operator!= (const char *string) const
 Lexicographically compare if this string is not equal to a given string.
 
 operator const char * () const
 Return an empty string.
 
int Compare (const BString &string) const
 Lexicographically compare this BString to another string.
 
int Compare (const char *string) const
 Lexicographically compare this BString to another string.
 
int Compare (const BString &string, int32 length) const
 Lexicographically compare length characters of this BString to another string.
 
int Compare (const char *string, int32 length) const
 Lexicographically compare length characters of this BString to another string.
 
int CompareAt (size_t offset, const BString &string, int32 length) const
 Lexicographically compare length of characters of this BString to another string, starting at offset.
 
int CompareChars (const BString &string, int32 charCount) const
 UTF-8 aware version of Compare(const BString&, int32).
 
int CompareChars (const char *string, int32 charCount) const
 UTF-8 aware version of Compare(const char*, int32).
 
int ICompare (const BString &string) const
 Lexicographically compare this BString to another string case-insensitively.
 
int ICompare (const char *string) const
 Lexicographically compare this BString to another string case-insensitively.
 
int ICompare (const BString &string, int32 length) const
 Lexicographically compare length characters of this BString to another string.
 
int ICompare (const char *string, int32 length) const
 Lexicographically compare length characters of this BString to another string.
 
Searching
int32 FindFirst (const BString &string) const
 Find the first occurrence of the given string.
 
int32 FindFirst (const char *string) const
 Find the first occurrence of the given string.
 
int32 FindFirst (const BString &string, int32 fromOffset) const
 Find the first occurrence of the given string starting from the given offset.
 
int32 FindFirst (const char *string, int32 fromOffset) const
 Find the first occurrence of the given string, starting from the given offset.
 
int32 FindFirst (char c) const
 Find the first occurrence of the given character.
 
int32 FindFirst (char c, int32 fromOffset) const
 Find the first occurrence of the given character, starting from the given offset.
 
int32 FindFirstChars (const BString &string, int32 fromCharOffset) const
 UTF-8 aware version of FindFirst(const BString&, int32).
 
int32 FindFirstChars (const char *string, int32 fromCharOffset) const
 UTF-8 aware version of FindFirst(const char*, int32).
 
int32 FindLast (const BString &string) const
 Find the last occurrence of the given string.
 
int32 FindLast (const char *string) const
 Find the last occurrence of the given string.
 
int32 FindLast (const BString &string, int32 beforeOffset) const
 Find the last occurrence of the given BString, starting from the given offset, and going backwards.
 
int32 FindLast (const char *string, int32 beforeOffset) const
 Find the last occurrence of the given string, starting from the given offset, and going backwards.
 
int32 FindLast (char c) const
 Find the last occurrence of the given character.
 
int32 FindLast (char c, int32 beforeOffset) const
 Find the last occurrence of the given character, starting from the given offset going backwards from the end.
 
int32 FindLastChars (const BString &string, int32 beforeCharOffset) const
 UTF-8 aware version of FindLast(const BString&, int32).
 
int32 FindLastChars (const char *string, int32 beforeCharOffset) const
 UTF-8 aware version of FindLast(const char*, int32).
 
int32 IFindFirst (const BString &string) const
 Find the first occurrence of the given string case-insensitively.
 
int32 IFindFirst (const char *string) const
 Find the first occurrence of the given string case-insensitively.
 
int32 IFindFirst (const BString &string, int32 fromOffset) const
 Find the first occurrence of the given BString case-insensitively, starting from the given offset.
 
int32 IFindFirst (const char *string, int32 fromOffset) const
 Find the first occurrence of the given string case-insensitively, starting from the given offset.
 
int32 IFindLast (const BString &string) const
 Find the last occurrence of the given BString case-insensitively.
 
int32 IFindLast (const char *string) const
 Find the last occurrence of the given string case-insensitively.
 
int32 IFindLast (const BString &string, int32 beforeOffset) const
 Find the last occurrence of the given BString case-insensitively, starting from the given offset going backwards.
 
int32 IFindLast (const char *string, int32 beforeOffset) const
 Find the last occurrence of the given string case-insensitively, starting from the given offset going backwards.
 
bool StartsWith (const BString &string) const
 Returns whether or not the BString starts with string.
 
bool StartsWith (const char *string) const
 Returns whether or not the BString starts with string.
 
bool StartsWith (const char *string, int32 length) const
 Returns whether or not the BString starts with length characters of string.
 
bool IStartsWith (const BString &string) const
 Returns whether or not the BString starts with string case-insensitively.
 
bool IStartsWith (const char *string) const
 Returns whether or not the BString starts with string case-insensitively.
 
bool IStartsWith (const char *string, int32 length) const
 Returns whether or not the BString starts with length characters of string case-insensitively.
 
bool EndsWith (const BString &string) const
 Returns whether or not the BString ends with string.
 
bool EndsWith (const char *string) const
 Returns whether or not the BString ends with string.
 
bool EndsWith (const char *string, int32 length) const
 Returns whether or not the BString ends with length characters of string.
 
bool IEndsWith (const BString &string) const
 Returns whether or not the BString ends with string case-insensitively.
 
bool IEndsWith (const char *string) const
 Returns whether or not the BString ends with string case-insensitively.
 
bool IEndsWith (const char *string, int32 length) const
 Returns whether or not the BString ends with length characters of string case-insensitively.
 
Replacing
BStringReplaceFirst (char replaceThis, char withThis)
 Replace the first occurrence of a character with another character.
 
BStringReplaceLast (char replaceThis, char withThis)
 Replace the last occurrence of a character with another character.
 
BStringReplaceAll (char replaceThis, char withThis, int32 fromOffset=0)
 Replace all occurrences of a character with another character.
 
BStringReplace (char replaceThis, char withThis, int32 maxReplaceCount, int32 fromOffset=0)
 Replace a number of occurrences of a character with another character.
 
BStringReplaceFirst (const char *replaceThis, const char *withThis)
 Replace the first occurrence of a string with another string.
 
BStringReplaceLast (const char *replaceThis, const char *withThis)
 Replace the last occurrence of a string with another string.
 
BStringReplaceAll (const char *replaceThis, const char *withThis, int32 fromOffset=0)
 Replace all occurrences of a string with another string.
 
BStringReplace (const char *replaceThis, const char *withThis, int32 maxReplaceCount, int32 fromOffset=0)
 Replace a number of occurrences of a string with another string.
 
BStringReplaceAllChars (const char *replaceThis, const char *withThis, int32 fromCharOffset)
 UTF-8 aware version of ReplaceAll(const char*, const char*, int32).
 
BStringReplaceChars (const char *replaceThis, const char *withThis, int32 maxReplaceCount, int32 fromCharOffset)
 UTF-8 aware version of ReplaceAll(const char*, const char*, int32, int32).
 
BStringIReplaceFirst (char replaceThis, char withThis)
 Replace the first occurrence of a character with another character case-insensitively.
 
BStringIReplaceLast (char replaceThis, char withThis)
 Replace the last occurrence of a character with another character case-insensitively.
 
BStringIReplaceAll (char replaceThis, char withThis, int32 fromOffset=0)
 Replace all occurrences of a character with another character case-insensitively.
 
BStringIReplace (char replaceThis, char withThis, int32 maxReplaceCount, int32 fromOffset=0)
 Replace a number of occurrences of a character with another character case-insensitively.
 
BStringIReplaceFirst (const char *replaceThis, const char *withThis)
 Replace the first occurrence of a string with another string case-insensitively.
 
BStringIReplaceLast (const char *replaceThis, const char *withThis)
 Replace the last occurrence of a string with another string. Case-insensitive.
 
BStringIReplaceAll (const char *replaceThis, const char *withThis, int32 fromOffset=0)
 Replace all occurrences of a string with another string case-insensitively.
 
BStringIReplace (const char *replaceThis, const char *withThis, int32 maxReplaceCount, int32 fromOffset=0)
 Replace a number of occurrences of a string with another string case-insensitively.
 
BStringReplaceSet (const char *setOfBytes, char with)
 Replaces characters that are in a certain set with a chosen character.
 
BStringReplaceSet (const char *setOfBytes, const char *with)
 Replaces characters that are in a certain set with a chosen string.
 
BStringReplaceCharsSet (const char *setOfChars, const char *with)
 UTF-8 aware version of ReplaceSet(const char*, const char*)
 
Indexing
char operator[] (int32 index) const
 Returns the character in the string at the given offset.
 
char ByteAt (int32 index) const
 Returns the character in the string at the given offset.
 
const char * CharAt (int32 charIndex, int32 *bytes=NULL) const
 UTF-8 aware version of ByteAt(int32).
 
bool CharAt (int32 charIndex, char *buffer, int32 *bytes) const
 UTF-8 aware version of ByteAt(int32) with a buffer parameter.
 
Low-Level Manipulation
char * LockBuffer (int32 maxLength)
 Locks the buffer and return the internal string for manipulation.
 
BStringUnlockBuffer (int32 length=-1)
 Unlocks the buffer after you are done with low-level manipulation.
 
BStringSetByteAt (int32 pos, char to)
 Set a byte at position pos to character to.
 
Case Manipulation
BStringToLower ()
 Convert each of the characters in the BString to lowercase.
 
BStringToUpper ()
 Convert each of the characters in the BString to uppercase.
 
BStringCapitalize ()
 Convert the first character to uppercase, and the rest to lowercase.
 
BStringCapitalizeEachWord ()
 Convert the first character of every word to uppercase, and the rest to lowercase.
 
Escaping and De-escaping

This class contains some methods to help you with escaping and de-escaping certain characters. Note that this is the C-style of escaping, where you place a character before the character that is to be escaped, and not HTML style escaping, where certain characters are replaced by something else.

BStringCharacterEscape (const char *original, const char *setOfCharsToEscape, char escapeWith)
 Escape selected characters on a given string.
 
BStringCharacterEscape (const char *setOfCharsToEscape, char escapeWith)
 Escape selected characters of this string.
 
BStringCharacterDeescape (const char *original, char escapeChar)
 Remove the character to escape with from a given string.
 
BStringCharacterDeescape (char escapeChar)
 Remove the character to escape with from this string.
 
sprintf() Replacement Methods

These methods may be slower than sprintf(), but they are overflow safe.

BStringoperator<< (const char *string)
 Append string to the BString.
 
BStringoperator<< (const BString &string)
 Append string to the BString.
 
BStringoperator<< (char c)
 Append c to the BString.
 
BStringoperator<< (bool value)
 Convert the bool value to a string and append it.
 
BStringoperator<< (int value)
 Convert the int value to a string and append it.
 
BStringoperator<< (unsigned int value)
 Convert the unsigned int value to a string and append it.
 
BStringoperator<< (unsigned long value)
 Convert the unsigned long value to a string and append it.
 
BStringoperator<< (long value)
 Convert the long value to a string and append it.
 
BStringoperator<< (unsigned long long value)
 Convert the unsigned long long value to a string and append it.
 
BStringoperator<< (long long value)
 Convert the long long value to a string and append it.
 
BStringoperator<< (float value)
 Convert the float value to a string and append it.
 
BStringoperator<< (double value)
 Convert the double value to a string and append it.
 

Access

const char * String () const
 Return a pointer to the object string, NUL terminated.
 
int32 Length () const
 Get the length of the string in bytes.
 
int32 CountChars () const
 Returns the length of the object measured in characters.
 
int32 CountBytes (int32 fromCharOffset, int32 charCount) const
 Count the number of bytes starting from a specified character.
 
bool IsEmpty () const
 Check whether the string is empty.
 
uint32 HashValue () const
 Return a hash value for the current string.
 
static uint32 HashValue (const char *string)
 Return the hash value of a specified string.
 

Detailed Description

String class supporting common string operations.

BString is a string allocation and manipulation class. The object takes care to allocate and free memory for you, so it will always be "big enough" to store your strings.

While BString is in essence a wrapper around a byte-array, which can always be accessed with the BString::String() method, it does have some understanding of UTF-8 and it can be used for the manipulation of UTF-8 strings. For all operations that perform on bytes, there is an equivalent that operates on UTF-8 strings. See for example the BString::CopyInto() and BString::CopyCharsInto() methods. The main difference is that if there are any position argumens, the regular method counts the bytes and the Chars methods counts characters.

Since
BeOS R5

Constructor & Destructor Documentation

◆ BString() [1/5]

BString::BString ( )

Creates an empty BString.

Since
BeOS R5

◆ BString() [2/5]

BString::BString ( const char *  string)

Creates and initializes a BString from string.

Parameters
stringThe string to copy from.
Since
BeOS R5

◆ BString() [3/5]

BString::BString ( const BString string)

Creates and initializes a BString as a copy of another string.

Parameters
stringThe BString object to copy from.
Since
BeOS R5

◆ BString() [4/5]

BString::BString ( const char *  string,
int32  maxLength 
)

Creates and initializes a BString from a string up to maxLength characters.

If maxLength is greater than the length of the source string then the entire source string is copied. If maxLength is less than or equal to 0 then the result is an empty BString.

Warning
In BeOS R5 passing in a negative maxLength argument will copy the entire string.
Parameters
stringThe string data to initialize the BString to.
maxLengthMaximum number of characters (bytes) to copy.
Since
BeOS R5

◆ BString() [5/5]

BString::BString ( BString &&  string)
noexcept

Move the data from the string to this object.

Create a new string object with the data of another string. The string will no longer point to the same contents.

Note
This constructor is only available for modern C++ (C++11 or later).
Since
Haiku R1

◆ ~BString()

BString::~BString ( )

Free all resources associated with the object.

The destructor also frees the internal buffer associated with the string.

Since
BeOS R5

Member Function Documentation

◆ Adopt() [1/2]

BString & BString::Adopt ( BString from)

Adopt the data of the given BString object.

This method adopts the data from a BString removing the data from from and putting it into the BString.

Warning
The object that is adopted from is not deleted, only its private data is initialized to a NULL string. If the from object was created on the heap you need to clean it up yourself.
Parameters
fromThe string data to adopt.
Returns
The function always returns *this.
See also
operator=(const BString&)
Since
BeOS R5

◆ Adopt() [2/2]

BString & BString::Adopt ( BString from,
int32  maxLength 
)

Adopt the data of the given BString object up to maxLength characters.

This method adopts the data from a BString removing the data from from and putting it into the BString.

Parameters
fromThe string object to adopt.
maxLengthMaximum number of characters (bytes) to adopt.
Returns
The function always returns *this.
See also
SetTo(const BString&, int32)
Since
BeOS R5

◆ AdoptChars()

BString & BString::AdoptChars ( BString from,
int32  charCount 
)

UTF-8 aware version of Adopt(BString&, int32)

Parameters
fromThe string data to start adopting from.
charCountNumber of UTF-8 characters to adopt.
Returns
This method always returns *this.
Since
Haiku R1

◆ Append() [1/5]

BString & BString::Append ( char  c,
int32  count 
)

Append the given character repeatedly to the end of the BString.

Parameters
cThe character to append.
countThe number of times this character should be appended.
Returns
This method always returns *this.
See also
operator+=(char c)
Since
BeOS R5

◆ Append() [2/5]

BString & BString::Append ( const BString string)
inline

Append the given string to the end of the BString.

Parameters
stringThe string to append.
Returns
This method always returns *this.
See also
Append(const BString&, int32)
Since
BeOS R5

References Length(), and String().

◆ Append() [3/5]

BString & BString::Append ( const BString string,
int32  length 
)

Append a part of the given string to the end of the BString.

Parameters
stringThe BString to append.
lengthThe maximum number of bytes to append.
Returns
This method always returns *this.
See also
operator+=(const BString&)
Since
BeOS R5

◆ Append() [4/5]

BString & BString::Append ( const char *  str)
inline

Append the string data to the end of the BString.

This method calls operator+=(const char *str).

See also
Append(const char*, int32)
Since
BeOS R5

References operator+=().

◆ Append() [5/5]

BString & BString::Append ( const char *  str,
int32  length 
)

Append a part of the given string to end of the BString.

Parameters
strA pointer to the string to append.
lengthThe maximum number of bytes to append.
Returns
This method always returns *this.
See also
operator+=(const char*)
Since
BeOS R5

◆ AppendChars() [1/2]

BString & BString::AppendChars ( const BString string,
int32  charCount 
)

UTF-8 aware version of Append(const BString&, int32).

Parameters
stringThe string to append.
charCountThe maximum number of UTF-8 characters to append.
Returns
This method always returns *this.
See also
Append(const BString&, int32)
Since
Haiku R1

◆ AppendChars() [2/2]

BString & BString::AppendChars ( const char *  string,
int32  charCount 
)

UTF-8 aware version of Append(const char*, int32).

Parameters
stringThe string to append.
charCountThe maximum number of UTF-8 characters to append.
Returns
This method always returns *this.
See also
Append(const char*, int32)
Since
Haiku R1

◆ ByteAt()

char BString::ByteAt ( int32  index) const
inline

Returns the character in the string at the given offset.

This function can be used to read a single byte.

Parameters
indexThe index (zero-based) of the byte to get.
Returns
A reference to the specified byte, if out of bounds return 0.
Since
BeOS R5

References Length().

◆ Capitalize()

BString & BString::Capitalize ( )

Convert the first character to uppercase, and the rest to lowercase.

Returns
This method always returns *this.
Since
BeOS R5

◆ CapitalizeEachWord()

BString & BString::CapitalizeEachWord ( )

Convert the first character of every word to uppercase, and the rest to lowercase.

Converts the first character of every "word" (series of alphabetical characters separated by non alphabetical characters) to uppercase, and the rest to lowercase.

Returns
This method always returns *this.
Since
BeOS R5

◆ CharacterDeescape() [1/2]

BString & BString::CharacterDeescape ( char  escapeChar)

Remove the character to escape with from this string.

Parameters
escapeCharThe character that was used to escape with.
Returns
This method always returns *this.
See also
CharacterEscape(const char*, char)

◆ CharacterDeescape() [2/2]

BString & BString::CharacterDeescape ( const char *  original,
char  escapeChar 
)

Remove the character to escape with from a given string.

This version sets itself to the string supplied in the original parameter, and then removes the escape characters.

Parameters
originalThe string to be escaped.
escapeCharThe character that was used to escape with.
Returns
This method always returns *this.
See also
CharacterEscape(const char*, const char*, char)
Since
BeOS R5

◆ CharacterEscape() [1/2]

BString & BString::CharacterEscape ( const char *  original,
const char *  setOfCharsToEscape,
char  escapeWith 
)

Escape selected characters on a given string.

This version sets itself to the string supplied in the original parameter, and then escapes the selected characters with a supplied character.

Parameters
originalThe string to be escaped.
setOfCharsToEscapeThe set of characters that need to be escaped.
escapeWithThe character to escape with.
Returns
This method always returns *this.
See also
CharacterDeescape(char)
CharacterDeescape(const char*, char)
Since
BeOS R5

◆ CharacterEscape() [2/2]

BString & BString::CharacterEscape ( const char *  setOfCharsToEscape,
char  escapeWith 
)

Escape selected characters of this string.

Parameters
setOfCharsToEscapeThe set of characters that need to be escaped.
escapeWithThe character to escape with.
Returns
This method always returns *this.
See also
CharacterDeescape(char)
Since
BeOS R5

◆ CharAt() [1/2]

bool BString::CharAt ( int32  charIndex,
char *  buffer,
int32 bytes 
) const

UTF-8 aware version of ByteAt(int32) with a buffer parameter.

Parameters
charIndexThe index (zero-based) of the UTF-8 character to get.
bufferSet to the position in the string where the character is found.
bytesAn int32 pointer to hold the UTF-8 character.
See also
ByteAt(int32, char*, int32*)
Since
Haiku R1

◆ CharAt() [2/2]

const char * BString::CharAt ( int32  charIndex,
int32 bytes = NULL 
) const

UTF-8 aware version of ByteAt(int32).

Parameters
charIndexThe index (zero-based) of the UTF-8 character to get.
bytesAn int32 pointer to hold the UTF-8 character.
Returns
A reference to the specified UTF-8 character, if out of bounds return 0.
See also
ByteAt(int32)
Since
Haiku R1

◆ Compare() [1/4]

int BString::Compare ( const BString string) const

Lexicographically compare this BString to another string.

Parameters
stringThe string to compare against.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
Since
BeOS R5

◆ Compare() [2/4]

int BString::Compare ( const BString string,
int32  length 
) const

Lexicographically compare length characters of this BString to another string.

Parameters
stringThe string to compare against.
lengthThe number of bytes to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
Since
BeOS R5

◆ Compare() [3/4]

int BString::Compare ( const char *  string) const

Lexicographically compare this BString to another string.

Parameters
stringThe string to compare against.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&) const
Since
BeOS R5

◆ Compare() [4/4]

int BString::Compare ( const char *  string,
int32  length 
) const

Lexicographically compare length characters of this BString to another string.

Parameters
stringThe string to compare against.
lengthThe number of bytes to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&, int32) const
Since
BeOS R5

◆ CompareAt()

int BString::CompareAt ( size_t  offset,
const BString string,
int32  length 
) const

Lexicographically compare length of characters of this BString to another string, starting at offset.

Parameters
offsetThe offset (in bytes) to start comparison.
stringThe string to compare against.
lengthThe number of bytes to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&, int32) const
Since
Haiku R1

◆ CompareChars() [1/2]

int BString::CompareChars ( const BString string,
int32  charCount 
) const

UTF-8 aware version of Compare(const BString&, int32).

Parameters
stringThe string to compare against.
charCountThe number of UTF-8 characters to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&, int32)
Since
Haiku R1

◆ CompareChars() [2/2]

int BString::CompareChars ( const char *  string,
int32  charCount 
) const

UTF-8 aware version of Compare(const char*, int32).

Parameters
stringThe string to compare against.
charCountThe number of UTF-8 characters to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const char*, int32)
Since
Haiku R1

◆ CopyCharsInto() [1/2]

BString & BString::CopyCharsInto ( BString into,
int32  fromOffset,
int32  charCount 
) const

UTF-8 aware version of CopyInto(BString&, int32, int32) const.

Parameters
intoThe BString to copy into.
fromOffsetThe (zero-based) offset in bytes where to begin the copy.
charCountThe number of UTF-8 characters to copy.
Returns
This method always returns a pointer to the string passed as the into parameter.
See also
CopyInto(BString&, int32, int32) const
Since
Haiku R1

◆ CopyCharsInto() [2/2]

bool BString::CopyCharsInto ( char *  into,
int32 intoLength,
int32  fromCharOffset,
int32  charCount 
) const

UTF-8 aware version of CopyInto(char*, int32, int32) const.

Parameters
intoThe buffer where to copy the object.
intoLengthThe length of into in bytes.
fromCharOffsetThe (zero-based) offset UTF-8 characters where to begin the copy.
charCountThe number of UTF-8 characters to copy.
See also
CopyInto(char*, int32, int32) const
Returns
false if into was NULL, true otherwise.
Since
Haiku R1

◆ CopyInto() [1/2]

BString & BString::CopyInto ( BString into,
int32  fromOffset,
int32  length 
) const

Copy the object's data (or part of it) into another BString.

This methods makes sure you don't copy more bytes than are available in the string. If the length exceeds the length of the string, it only copies the number of characters that are actually available.

Parameters
intoThe BString to copy into.
fromOffsetThe (zero-based) offset where to begin the copy.
lengthThe number of bytes to copy.
Returns
This method always returns a pointer to the string passed as the into parameter.
Since
BeOS R5

◆ CopyInto() [2/2]

void BString::CopyInto ( char *  into,
int32  fromOffset,
int32  length 
) const

Copy the BString data (or part of it) into the supplied buffer.

This methods makes sure you don't copy more bytes than are available in the string. If the length exceeds the length of the string, it only copies the number of characters that are actually available.

It's up to you to make sure your buffer is large enough.

Parameters
intoThe buffer where to copy the object.
fromOffsetThe (zero-based) offset where to begin the copy.
lengthThe number of bytes to copy.
Since
BeOS R5

◆ CountBytes()

int32 BString::CountBytes ( int32  fromCharOffset,
int32  charCount 
) const

Count the number of bytes starting from a specified character.

BString is somewhat aware of UTF-8 characters, which can take up more than one byte. With this method you can count the number of bytes a subset of the string contains.

Warning
This method does not check whether the input is outside of the boundaries, so make sure that you check your input values.
Parameters
fromCharOffsetThe index of the character (not the byte!) from which to start the count
charCountThe number of characters to count
Returns
An integer with the number of bytes.
Since
Haiku R1

◆ CountChars()

int32 BString::CountChars ( ) const

Returns the length of the object measured in characters.

BString is somewhat aware of UTF-8 characters, so this method will count the actual number of characters in the string.

Returns
An integer which is the number of characters in the string.
See also
Length()
Since
BeOS R5

◆ EndsWith() [1/3]

bool BString::EndsWith ( const BString string) const

Returns whether or not the BString ends with string.

Parameters
stringThe string to search for.
Returns
true if the BString ended with string, false otherwise.
Since
Haiku R1

◆ EndsWith() [2/3]

bool BString::EndsWith ( const char *  string) const

Returns whether or not the BString ends with string.

Parameters
stringThe string to search for.
Returns
true if the BString ended with string, false otherwise.
Since
Haiku R1

◆ EndsWith() [3/3]

bool BString::EndsWith ( const char *  string,
int32  length 
) const

Returns whether or not the BString ends with length characters of string.

Parameters
stringThe string to search for.
lengthThe number of characters (bytes) of string to search for.
Returns
true if the BString ended with length characters of string, false otherwise.
Since
Haiku R1

◆ FindFirst() [1/6]

int32 BString::FindFirst ( char  c) const

Find the first occurrence of the given character.

Parameters
cThe character to search for.
Returns
The offset (zero-based) into the data where the given character was found, or B_ERROR if we could not find the character.
Since
BeOS R5

◆ FindFirst() [2/6]

int32 BString::FindFirst ( char  c,
int32  fromOffset 
) const

Find the first occurrence of the given character, starting from the given offset.

Parameters
cThe character to search for.
fromOffsetThe offset where to start the search.
Returns
The offset (zero-based) into the data where the given character was found, or B_ERROR if we could not find the character.
Since
BeOS R5

◆ FindFirst() [3/6]

int32 BString::FindFirst ( const BString string) const

Find the first occurrence of the given string.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given BString was found or B_ERROR if we could not find string.
See also
IFindFirst(const BString&) const
Since
BeOS R5

◆ FindFirst() [4/6]

int32 BString::FindFirst ( const BString string,
int32  fromOffset 
) const

Find the first occurrence of the given string starting from the given offset.

Parameters
stringThe string to search for.
fromOffsetThe offset in bytes to start the search.
Returns
An integer which is the offset (zero-based) into the data where the given BString was found or B_ERROR if we could not find the string.
See also
IFindFirst(const BString&, int32) const
StartsWith(const char*, int32) const
Since
BeOS R5

◆ FindFirst() [5/6]

int32 BString::FindFirst ( const char *  string) const

Find the first occurrence of the given string.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find string.
See also
IFindFirst(const char*) const
StartsWith(const char*) const
StartsWith(const char*, int32) const
Since
BeOS R5

◆ FindFirst() [6/6]

int32 BString::FindFirst ( const char *  string,
int32  fromOffset 
) const

Find the first occurrence of the given string, starting from the given offset.

Parameters
stringThe string to search for.
fromOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindFirst(const char*, int32) const
Since
BeOS R5

◆ FindFirstChars() [1/2]

int32 BString::FindFirstChars ( const BString string,
int32  fromCharOffset 
) const

UTF-8 aware version of FindFirst(const BString&, int32).

Parameters
stringThe string to search for.
fromCharOffsetThe offset in UTF-8 characters to start the search.
Returns
An integer which is the offset (zero-based) into the data where the given BString was found or B_ERROR if we could not find the string.
See also
FindFirst(const BString&, int32)
Since
Haiku R1

◆ FindFirstChars() [2/2]

int32 BString::FindFirstChars ( const char *  string,
int32  fromCharOffset 
) const

UTF-8 aware version of FindFirst(const char*, int32).

Parameters
stringThe string to search for.
fromCharOffsetThe offset in UTF-8 characters to start the search.
See also
FindChars(const char*, int32)
Since
Haiku R1

◆ FindLast() [1/6]

int32 BString::FindLast ( char  c) const

Find the last occurrence of the given character.

Parameters
cThe character to search for.
Returns
The offset (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the character.
Since
BeOS R5

◆ FindLast() [2/6]

int32 BString::FindLast ( char  c,
int32  beforeOffset 
) const

Find the last occurrence of the given character, starting from the given offset going backwards from the end.

Parameters
cThe character to search for.
beforeOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given character was found, or B_ERROR Could not find the character.
Since
BeOS R5

◆ FindLast() [3/6]

int32 BString::FindLast ( const BString string) const

Find the last occurrence of the given string.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the string.
See also
IFindLast(const BString&) const
EndsWith(const BString&) const
Since
BeOS R5

◆ FindLast() [4/6]

int32 BString::FindLast ( const BString string,
int32  beforeOffset 
) const

Find the last occurrence of the given BString, starting from the given offset, and going backwards.

Parameters
stringThe BString to search for.
beforeOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the string.
See also
IFindLast(const BString&, int32) const
Since
BeOS R5

◆ FindLast() [5/6]

int32 BString::FindLast ( const char *  string) const

Find the last occurrence of the given string.

Parameters
stringThe string to search for.
Returns
The offset in bytes (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindLast(const char*) const
EndsWith(const char*) const
EndsWith(const char*, int32) const
Since
BeOS R5

◆ FindLast() [6/6]

int32 BString::FindLast ( const char *  string,
int32  beforeOffset 
) const

Find the last occurrence of the given string, starting from the given offset, and going backwards.

Parameters
stringThe string to search for.
beforeOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindLast(const char*, int32) const
Since
BeOS R5

◆ FindLastChars() [1/2]

int32 BString::FindLastChars ( const BString string,
int32  beforeCharOffset 
) const

UTF-8 aware version of FindLast(const BString&, int32).

Parameters
stringThe BString to search for.
beforeCharOffsetThe offset in UTF-8 characters to start the search.
Returns
The offset in bytes (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the string.
See also
FindLast(const BString&, int32)
Since
Haiku R1

◆ FindLastChars() [2/2]

int32 BString::FindLastChars ( const char *  string,
int32  beforeCharOffset 
) const

UTF-8 aware version of FindLast(const char*, int32).

Parameters
stringThe string to search for.
beforeCharOffsetThe offset in UTF-8 characters to start the search.
Returns
The offset in bytes (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
FindLast(const char*, int32)
Since
Haiku R1

◆ HashValue() [1/2]

uint32 BString::HashValue ( ) const
inline

Return a hash value for the current string.

See also
HashValue(const char*)
Since
Haiku R1

References HashValue(), and String().

Referenced by HashValue().

◆ HashValue() [2/2]

static uint32 BString::HashValue ( const char *  string)
static

Return the hash value of a specified string.

This allows you to use the BString::HashValue() method on any arbitrary string.

Parameters
stringThe string that you want to have hashed.
See also
HashValue()
Since
Haiku R1

◆ ICompare() [1/4]

int BString::ICompare ( const BString string) const

Lexicographically compare this BString to another string case-insensitively.

Parameters
stringThe string to compare against.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&) const
Since
BeOS R5

◆ ICompare() [2/4]

int BString::ICompare ( const BString string,
int32  length 
) const

Lexicographically compare length characters of this BString to another string.

Parameters
stringThe string to compare against.
lengthThe number of characters to compare.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&, int32) const
Since
BeOS R5

◆ ICompare() [3/4]

int BString::ICompare ( const char *  string) const

Lexicographically compare this BString to another string case-insensitively.

Parameters
stringThe string to compare against.
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&) const
Since
BeOS R5

◆ ICompare() [4/4]

int BString::ICompare ( const char *  string,
int32  length 
) const

Lexicographically compare length characters of this BString to another string.

Parameters
stringThe string to compare against.
lengthThe number of characters to compare
Returns
An int representing the strings relationship to each other.
Return values
>0The BString sorts lexicographically after string.
=0The BString is equal to string.
<0The BString sorts lexicographically before string.
See also
Compare(const BString&, int32) const
Since
BeOS R5

◆ IEndsWith() [1/3]

bool BString::IEndsWith ( const BString string) const

Returns whether or not the BString ends with string case-insensitively.

Parameters
stringThe string to search for.
Returns
true if the BString ended with string case-insensitively, false otherwise.
Since
Haiku R1

◆ IEndsWith() [2/3]

bool BString::IEndsWith ( const char *  string) const

Returns whether or not the BString ends with string case-insensitively.

Parameters
stringThe string to search for.
Returns
true if the BString ended with string case-insensitively, false otherwise.
Since
Haiku R1

◆ IEndsWith() [3/3]

bool BString::IEndsWith ( const char *  string,
int32  length 
) const

Returns whether or not the BString ends with length characters of string case-insensitively.

Parameters
stringThe string to search for.
lengthThe number of characters (bytes) of string to search for.
Returns
true if the BString ended with length characters of string case-insensitively, false otherwise.
Since
Haiku R1

◆ IFindFirst() [1/4]

int32 BString::IFindFirst ( const BString string) const

Find the first occurrence of the given string case-insensitively.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given BString was found or B_ERROR if we could not find string.
See also
IFindFirst(const BString&) const
Since
BeOS R5

◆ IFindFirst() [2/4]

int32 BString::IFindFirst ( const BString string,
int32  fromOffset 
) const

Find the first occurrence of the given BString case-insensitively, starting from the given offset.

Parameters
stringThe string to search for.
fromOffsetThe offset in bytes to start the search.
Returns
An integer which is the offset (zero-based) into the data where the given BString was found or B_ERROR if we could not find the string.
See also
IFindFirst(const BString&, int32) const
StartsWith(const char*, int32) const
Since
BeOS R5

◆ IFindFirst() [3/4]

int32 BString::IFindFirst ( const char *  string) const

Find the first occurrence of the given string case-insensitively.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find string.
See also
IFindFirst(const char*) const
StartsWith(const char*) const
StartsWith(const char*, int32) const
Since
BeOS R5

◆ IFindFirst() [4/4]

int32 BString::IFindFirst ( const char *  string,
int32  fromOffset 
) const

Find the first occurrence of the given string case-insensitively, starting from the given offset.

Parameters
stringThe string to search for.
fromOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindFirst(const char*, int32) const
Since
BeOS R5

◆ IFindLast() [1/4]

int32 BString::IFindLast ( const BString string) const

Find the last occurrence of the given BString case-insensitively.

Parameters
stringThe string to search for.
Returns
The offset (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the string.
See also
IFindLast(const BString&) const
EndsWith(const BString&) const
Since
BeOS R5

◆ IFindLast() [2/4]

int32 BString::IFindLast ( const BString string,
int32  beforeOffset 
) const

Find the last occurrence of the given BString case-insensitively, starting from the given offset going backwards.

Parameters
stringThe BString to search for.
beforeOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given BString was found, or B_ERROR if we could not find the string.
See also
IFindLast(const BString&, int32) const
Since
BeOS R5

◆ IFindLast() [3/4]

int32 BString::IFindLast ( const char *  string) const

Find the last occurrence of the given string case-insensitively.

Parameters
stringThe string to search for.
Returns
The offset in bytes (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindLast(const char*) const
EndsWith(const char*) const
EndsWith(const char*, int32) const
Since
BeOS R5

◆ IFindLast() [4/4]

int32 BString::IFindLast ( const char *  string,
int32  beforeOffset 
) const

Find the last occurrence of the given string case-insensitively, starting from the given offset going backwards.

Parameters
stringThe string to search for.
beforeOffsetThe offset in bytes to start the search.
Returns
The offset (zero-based) into the data where the given string was found, B_BAD_VALUE if the string pointer is invalid, or B_ERROR if we could not find the string.
See also
IFindLast(const char*, int32) const
Since
BeOS R5

◆ Insert() [1/7]

BString & BString::Insert ( char  c,
int32  count,
int32  pos 
)

Inserts the given character repeatedly at the given position into the BString data.

Parameters
cThe character to insert.
countThe number of times to insert the character.
posThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
Since
BeOS R5

◆ Insert() [2/7]

BString & BString::Insert ( const BString string,
int32  fromOffset,
int32  length,
int32  position 
)

Inserts the given string at the given position into the BString data.

Parameters
stringThe string to insert.
fromOffsetThe offset in bytes of the string to be inserted.
lengthThe amount of bytes to insert.
positionThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
See also
Insert(const BString&, int32)
Insert(const BString&, int32, int32)
Since
BeOS R5

◆ Insert() [3/7]

BString & BString::Insert ( const BString string,
int32  length,
int32  position 
)

Inserts the given BString at the given position into the BString data.

Parameters
stringThe string to insert.
lengthThe number of bytes to insert.
positionThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
See also
Insert(const BString&, int32)
Insert(const BString&, int32, int32, int32)
Since
BeOS R5

◆ Insert() [4/7]

BString & BString::Insert ( const BString string,
int32  position 
)

Inserts the given BString at the given position into the BString data.

Parameters
stringThe string to insert.
positionThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
See also
Insert(const BString&, int32, int32)
Insert(const BString&, int32, int32, int32)
Since
BeOS R5

◆ Insert() [5/7]

BString & BString::Insert ( const char *  string,
int32  fromOffset,
int32  length,
int32  position 
)

Inserts the given string at the given position into the BString data.

Parameters
stringThe string to insert.
fromOffsetThe offset in bytes in the string to be inserted.
lengthThe number of bytes to insert.
positionThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
See also
Insert(const char*, int32)
Insert(const char*, int32, int32)
Since
BeOS R5

◆ Insert() [6/7]

BString & BString::Insert ( const char *  string,
int32  length,
int32  position 
)

Inserts the given string at the given position into the BString data.

Parameters
stringThe string to insert.
lengthThe number of bytes to insert.
positionThe offset in bytes into the data of the BString where to insert the string.
Returns
This method always returns *this.
See also
Insert(const char*, int32)
Insert(const char*, int32, int32, int32)
Since
BeOS R5

◆ Insert() [7/7]

BString & BString::Insert ( const char *  string,
int32  position 
)

Inserts the given string at the given position into the BString data.

Parameters
stringThe string to insert.
positionThe offset in bytes where to insert the string into the BString's data.
Returns
This method always returns *this.
See also
Insert(const char*, int32, int32)
Insert(const char*, int32, int32, int32)
Since
BeOS R5

◆ InsertChars() [1/6]

BString & BString::InsertChars ( const BString string,
int32  charCount,
int32  charPosition 
)

UTF-8 aware version of Insert(const BString&, int32, int32).

Parameters
stringThe string to insert.
charCountThe number of UTF-8 characters to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const BString&, int32, int32)
Since
Haiku R1

◆ InsertChars() [2/6]

BString & BString::InsertChars ( const BString string,
int32  charPosition 
)

UTF-8 aware version of Insert(const BString&, int32).

Parameters
stringThe string to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const BString&, int32)
Since
Haiku R1

◆ InsertChars() [3/6]

BString & BString::InsertChars ( const BString string,
int32  fromCharOffset,
int32  charCount,
int32  charPosition 
)

UTF-8 aware version of Insert(const BString&, int32, int32, int32).

Parameters
stringThe string to insert.
fromCharOffsetThe offset in UTF-8 characters of the string to be inserted.
charCountThe number of UTF-8 characters to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const BString&, int32, int32, int32)
Since
Haiku R1

◆ InsertChars() [4/6]

BString & BString::InsertChars ( const char *  string,
int32  charCount,
int32  charPosition 
)

UTF-8 aware version of Insert(const char*, int32, int32).

Parameters
stringThe string to insert.
charCountThe number of UTF-8 characters to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const char*, int32, int32)
Since
Haiku R1

◆ InsertChars() [5/6]

BString & BString::InsertChars ( const char *  string,
int32  charPosition 
)

UTF-8 aware version of Insert(const char*, int32).

Parameters
stringThe string to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const char*, int32)
Since
Haiku R1

◆ InsertChars() [6/6]

BString & BString::InsertChars ( const char *  string,
int32  fromCharOffset,
int32  charCount,
int32  charPosition 
)

UTF-8 aware version of Insert(const char*, int32, int32, int32).

Parameters
stringThe string to insert.
fromCharOffsetThe offset in UTF-8 characters of the string to be inserted.
charCountThe number of UTF-8 characters to insert.
charPositionThe offset in UTF-8 characters where to insert the string into the data of the BString.
Returns
This method always returns *this.
See also
Insert(const char*, int32, int32, int32)
Since
Haiku R1

◆ IReplace() [1/2]

BString & BString::IReplace ( char  replaceThis,
char  withThis,
int32  maxReplaceCount,
int32  fromOffset = 0 
)

Replace a number of occurrences of a character with another character case-insensitively.

Parameters
replaceThisThe char to replace.
withThisThe char to put in its place
maxReplaceCountThe maximum number of occurrences that should be replaced.
fromOffsetThe offset where to start looking for the string
See also
Replace(char, char, int32, int32)
Since
BeOS R5

◆ IReplace() [2/2]

BString & BString::IReplace ( const char *  replaceThis,
const char *  withThis,
int32  maxReplaceCount,
int32  fromOffset = 0 
)

Replace a number of occurrences of a string with another string case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
maxReplaceCountThe maximum number of occurrences that should be replaced.
fromOffsetThe offset where to start looking for the string
See also
Replace(const char*, const char*, int32, int32)
Since
BeOS R5

◆ IReplaceAll() [1/2]

BString & BString::IReplaceAll ( char  replaceThis,
char  withThis,
int32  fromOffset = 0 
)

Replace all occurrences of a character with another character case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
fromOffsetThe offset where to start looking for the string
See also
ReplaceAll(char, char, int32)
Since
BeOS R5

◆ IReplaceAll() [2/2]

BString & BString::IReplaceAll ( const char *  replaceThis,
const char *  withThis,
int32  fromOffset = 0 
)

Replace all occurrences of a string with another string case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place.
fromOffsetThe offset where to start looking for the string.
See also
ReplaceAll(const char*, const char*, int32)
Since
BeOS R5

◆ IReplaceFirst() [1/2]

BString & BString::IReplaceFirst ( char  replaceThis,
char  withThis 
)

Replace the first occurrence of a character with another character case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
See also
ReplaceFirst(char, char)
Since
BeOS R5

◆ IReplaceFirst() [2/2]

BString & BString::IReplaceFirst ( const char *  replaceThis,
const char *  withThis 
)

Replace the first occurrence of a string with another string case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place.
See also
ReplaceFirst(const char*, const char*)
Since
BeOS R5

◆ IReplaceLast() [1/2]

BString & BString::IReplaceLast ( char  replaceThis,
char  withThis 
)

Replace the last occurrence of a character with another character case-insensitively.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
See also
ReplaceLast(char, char)
Since
BeOS R5

◆ IReplaceLast() [2/2]

BString & BString::IReplaceLast ( const char *  replaceThis,
const char *  withThis 
)

Replace the last occurrence of a string with another string. Case-insensitive.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place.
See also
ReplaceLast(const char*, const char*)
Since
BeOS R5

◆ IsEmpty()

bool BString::IsEmpty ( ) const
inline

Check whether the string is empty.

Returns
Returns true if the string is empty.
Since
Haiku R1

References Length().

◆ IStartsWith() [1/3]

bool BString::IStartsWith ( const BString string) const

Returns whether or not the BString starts with string case-insensitively.

Parameters
stringThe string to search for.
Returns
true if the BString started with string case-insensitively, false otherwise.
Since
Haiku R1

◆ IStartsWith() [2/3]

bool BString::IStartsWith ( const char *  string) const

Returns whether or not the BString starts with string case-insensitively.

Parameters
stringThe string to search for.
Returns
true if the BString started with string case-insensitively, false otherwise.
Since
Haiku R1

◆ IStartsWith() [3/3]

bool BString::IStartsWith ( const char *  string,
int32  length 
) const

Returns whether or not the BString starts with length characters of string case-insensitively.

Parameters
stringThe string to search for.
lengthThe number of characters (bytes) of string to search for.
Returns
true if the BString started with length characters of string case-insensitively, false otherwise.
Since
Haiku R1

◆ Length()

int32 BString::Length ( ) const
inline

Get the length of the string in bytes.

Returns
An integer with the length of the string, measured in bytes.
See also
CountChars()
Since
BeOS R5

Referenced by Append(), ByteAt(), IsEmpty(), and operator+=().

◆ LockBuffer()

char * BString::LockBuffer ( int32  maxLength)

Locks the buffer and return the internal string for manipulation.

If you want to do any low-level string manipulation on the internal buffer, you should call this method. This method includes the possibility to grow the buffer so that you don't have to worry about that yourself.

Make sure you call UnlockBuffer() when you're done with the manipulation.

Parameters
maxLengthThe size of the buffer in bytes. If you don't want a bigger buffer, passing anything under the length of the string will simply return it as is.
Returns
A pointer to the buffer to manipulate.
See also
UnlockBuffer()
Since
BeOS R5

◆ MoveCharsInto() [1/2]

BString & BString::MoveCharsInto ( BString into,
int32  fromCharOffset,
int32  charCount 
)

UTF-8 aware version of MoveInto(BString&, int32, int32)

Parameters
intoThe BString where to move the string into.
fromCharOffsetThe offset (zero-based) in UTF-8 characters where to begin the move.
charCountThe number of UTF-8 characters to move.
See also
MoveInto(BString&, int32, int32)
Since
Haiku R1

◆ MoveCharsInto() [2/2]

bool BString::MoveCharsInto ( char *  into,
int32 intoLength,
int32  fromCharOffset,
int32  charCount 
)

UTF-8 aware version of MoveInto(char*, int32*, int32, int32).

Parameters
intoThe buffer to move the string into.
intoLengthThe offset (zero-based) in bytes where to begin the move.
fromCharOffsetThe offset (zero-based) in UTF-8 characters where to begin the move.
charCountThe number of UTF-8 characters to move.
Returns
false if into was NULL, true otherwise.
See also
MoveInto(char*, int32*, int32, int32)
Since
Haiku R1

◆ MoveInto() [1/2]

BString & BString::MoveInto ( BString into,
int32  from,
int32  length 
)

Move the BString data (or part of it) into another BString.

Parameters
intoThe BString to move the string into.
fromThe offset (zero-based) in bytes where to begin the move.
lengthThe number of bytes to move.
Returns
This method always returns into.
Since
BeOS R5

◆ MoveInto() [2/2]

void BString::MoveInto ( char *  into,
int32  from,
int32  length 
)

Move the BString data (or part of it) into the given buffer.

Parameters
intoThe buffer to move the string into.
fromThe offset (zero-based) in bytes where to begin the move.
lengthThe number of bytes to move.
Since
BeOS R5

◆ operator const char *()

BString::operator const char * ( ) const
inline

Return an empty string.

Returns
An empty string.
Since
Haiku R1

◆ operator!=() [1/2]

bool BString::operator!= ( const BString string) const
inline

Lexicographically compare if this BString is not equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

◆ operator!=() [2/2]

bool BString::operator!= ( const char *  string) const
inline

Lexicographically compare if this string is not equal to a given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References operator==().

◆ operator+=() [1/3]

BString & BString::operator+= ( char  c)

Append the given character to the end of the BString.

Parameters
cThe character to append.
Returns
This method always returns *this.
See also
Append(char, int32)

◆ operator+=() [2/3]

BString & BString::operator+= ( const BString string)
inline

Append the given string to the end of the BString.

Parameters
stringThe string to append.
Returns
This method always returns *this.
See also
Append(const BString&, int32)
Since
BeOS R5

References Length(), and String().

Referenced by Append().

◆ operator+=() [3/3]

BString & BString::operator+= ( const char *  str)

Append the given string to the end of the BString.

Parameters
strA pointer to the NULL-terminated string to append.
Returns
This method always returns *this.
See also
Append(const char*, int32)
Since
BeOS R5

◆ operator<() [1/2]

bool BString::operator< ( const BString string) const
inline

Lexicographically compare if this BString is less than the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

◆ operator<() [2/2]

bool BString::operator< ( const char *  string) const

Lexicographically compare if this BString is less than the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

◆ operator<<() [1/12]

BString & BString::operator<< ( bool  value)

Convert the bool value to a string and append it.

In case the value is true, the string "true" is appended to the string. Otherwise, the string "false" is appended.

Parameters
valueThe boolean value ("true" of "false") to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [2/12]

BString & BString::operator<< ( char  c)

Append c to the BString.

Parameters
cThe character to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [3/12]

BString & BString::operator<< ( const BString string)

Append string to the BString.

Parameters
stringThe string to append.
Returns
This method always returns *this.

◆ operator<<() [4/12]

BString & BString::operator<< ( const char *  string)

Append string to the BString.

Parameters
stringThe string to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [5/12]

BString & BString::operator<< ( double  value)

Convert the double value to a string and append it.

Using this operator will append using %.2f formatting.

Parameters
valueThe double value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [6/12]

BString & BString::operator<< ( float  value)

Convert the float value to a string and append it.

Using this operator will append using %.2f formatting.

Parameters
valueThe float value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [7/12]

BString & BString::operator<< ( int  value)

Convert the int value to a string and append it.

Parameters
valueThe int value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [8/12]

BString & BString::operator<< ( long long  value)

Convert the long long value to a string and append it.

Parameters
valueThe long long value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [9/12]

BString & BString::operator<< ( long  value)

Convert the long value to a string and append it.

Parameters
valueThe long value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [10/12]

BString & BString::operator<< ( unsigned int  value)

Convert the unsigned int value to a string and append it.

Parameters
valueThe unsigned int value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [11/12]

BString & BString::operator<< ( unsigned long long  value)

Convert the unsigned long long value to a string and append it.

Parameters
valueThe unsigned long long value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<<() [12/12]

BString & BString::operator<< ( unsigned long  value)

Convert the unsigned long value to a string and append it.

Parameters
valueThe unsigned long value to append.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator<=() [1/2]

bool BString::operator<= ( const BString string) const
inline

Lexicographically compare if this BString is less than or equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

◆ operator<=() [2/2]

bool BString::operator<= ( const char *  string) const

Lexicographically compare if this BString is less than or equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

◆ operator=() [1/4]

BString & BString::operator= ( BString &&  string)
noexcept

Move the contents of string to this BString object.

The string will no longer point to the same contents.

Note
This method is only available for modern C++ (C++11 or later).
Returns
This method always returns *this.
Since
Haiku R1

◆ operator=() [2/4]

BString & BString::operator= ( char  c)

Re-initialize the BString to a character.

Parameters
cThe char to re-initialize the BString to.
Returns
This method always returns *this.
Since
BeOS R5

◆ operator=() [3/4]

BString & BString::operator= ( const BString string)

Re-initialize the object to a copy of the data of a BString.

Parameters
stringThe string to copy.
Returns
The function always returns *this.
See also
Adopt(BString&)
SetTo(const BString&, int32)
Since
BeOS R5

Referenced by SetTo().

◆ operator=() [4/4]

BString & BString::operator= ( const char *  str)

Re-initialize the BString to a copy of the data of a string.

Parameters
strThe string data to re-initialize the BString to.
Returns
This method always returns *this.
See also
SetTo(const char*, int32)
Since
BeOS R5

◆ operator==() [1/2]

bool BString::operator== ( const BString string) const
inline

Lexicographically compare if this BString is equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

Referenced by operator!=().

◆ operator==() [2/2]

bool BString::operator== ( const char *  string) const

Lexicographically compare if this BString is equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

◆ operator>() [1/2]

bool BString::operator> ( const BString string) const
inline

Lexicographically compare if this BString is greater than the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

◆ operator>() [2/2]

bool BString::operator> ( const char *  string) const

Lexicographically compare if this string is more than a given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

◆ operator>=() [1/2]

bool BString::operator>= ( const BString string) const
inline

Lexicographically compare if this BString is greater than or equal to the given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

References String().

◆ operator>=() [2/2]

bool BString::operator>= ( const char *  string) const

Lexicographically compare if this string is more than or equal to a given string.

Parameters
stringThe string to compare against.
Since
BeOS R5

◆ operator[]()

char BString::operator[] ( int32  index) const
inline

Returns the character in the string at the given offset.

This function can be used to read a byte. There is no bound checking though, use ByteAt() if you don't know if the index parameter is valid.

Parameters
indexThe index (zero-based) of the byte to get.
Returns
Returns a reference to the specified byte.
Since
BeOS R5

◆ Prepend() [1/5]

BString & BString::Prepend ( char  c,
int32  count 
)

Prepend the given character count times to the beginning of the BString.

Parameters
cThe character to prepend.
countThe number of times this character should be prepended.
Returns
This method always returns *this.
Since
BeOS R5

◆ Prepend() [2/5]

BString & BString::Prepend ( const BString string)

Prepend the given BString to the beginning of the BString.

Parameters
stringThe string to prepend.
Returns
This method always returns *this.
See also
Prepend(const BString&, int32)
Since
BeOS R5

◆ Prepend() [3/5]

BString & BString::Prepend ( const BString string,
int32  length 
)

Prepend the given BString to the beginning of the BString.

Parameters
stringThe string to prepend.
lengthThe maximum number of bytes to prepend.
Returns
This method always returns *this.
See also
Prepend(const BString&)
Since
BeOS R5

◆ Prepend() [4/5]

BString & BString::Prepend ( const char *  str)

Prepend the given string to the beginning of the BString.

Parameters
strThe string to prepend.
Returns
This method always returns *this.
See also
Prepend(const char*, int32)
Since
BeOS R5

◆ Prepend() [5/5]

BString & BString::Prepend ( const char *  str,
int32  length 
)

Prepend the given string to the beginning of the BString.

Parameters
strThe string to prepend.
lengthThe maximum number of bytes to prepend.
Returns
This method always returns *this.
See also
Prepend(const char*)
Since
BeOS R5

◆ PrependChars() [1/2]

BString & BString::PrependChars ( const BString string,
int32  charCount 
)

UTF-8 aware version of Prepend(const BString&, int32).

Parameters
stringThe string to prepend.
charCountThe maximum number of UTF-8 characters to prepend.
Returns
This method always returns *this.
See also
Prepend(const BString&, int32)
Since
Haiku R1

◆ PrependChars() [2/2]

BString & BString::PrependChars ( const char *  string,
int32  charCount 
)

UTF-8 aware version of Prepend(const char*, int32).

Parameters
stringThe string to prepend.
charCountThe maximum number of UTF-8 characters to prepend.
Returns
This method always returns *this.
See also
Prepend(const char*, int32)
Since
Haiku R1

◆ Remove()

BString & BString::Remove ( int32  from,
int32  length 
)

Remove some bytes, starting at the given offset.

Parameters
fromThe offset in bytes to start removing.
lengthThe number of bytes to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveAll() [1/2]

BString & BString::RemoveAll ( const BString string)

Remove all occurrences of the given BString.

Parameters
stringThe BString to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveAll() [2/2]

BString & BString::RemoveAll ( const char *  str)

Remove all occurrences of the given string.

Parameters
strA pointer to the string to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveChars()

BString & BString::RemoveChars ( int32  fromCharOffset,
int32  charCount 
)

UTF-8 aware version of Remove(int32, int32).

Parameters
fromCharOffsetThe offset in UTF-8 characters to start removing.
charCountThe number of UTF-8 characters to remove.
Returns
This function always returns *this.
See also
Remove(int32, int32)
Since
Haiku R1

◆ RemoveCharsSet()

BString & BString::RemoveCharsSet ( const char *  setOfCharsToRemove)

UTF-8 aware version of RemoveSet(const char*).

Parameters
setOfCharsToRemoveThe set of characters to remove.
Returns
This function always returns *this.
See also
RemoveSet(const char*)
Since
Haiku R1

◆ RemoveFirst() [1/2]

BString & BString::RemoveFirst ( const BString string)

Remove the first occurrence of the given BString.

Parameters
stringThe BString to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveFirst() [2/2]

BString & BString::RemoveFirst ( const char *  string)

Remove the first occurrence of the given string.

Parameters
stringA pointer to the string to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveLast() [1/2]

BString & BString::RemoveLast ( const BString string)

Remove the last occurrence of the given BString.

Parameters
stringThe BString to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveLast() [2/2]

BString & BString::RemoveLast ( const char *  string)

Remove the last occurrence of the given string.

Parameters
stringA pointer to the string to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ RemoveSet()

BString & BString::RemoveSet ( const char *  setOfCharsToRemove)

Remove all the characters specified.

Parameters
setOfCharsToRemoveThe set of characters to remove.
Returns
This function always returns *this.
Since
BeOS R5

◆ Replace() [1/2]

BString & BString::Replace ( char  replaceThis,
char  withThis,
int32  maxReplaceCount,
int32  fromOffset = 0 
)

Replace a number of occurrences of a character with another character.

Parameters
replaceThisThe character to replace.
withThisThe character to put in its place
maxReplaceCountThe maximum number of characters that should be replaced.
fromOffsetThe offset in bytes to start looking for the character
Returns
This method always returns *this.
See also
IReplace(char, char, int32, int32)
Since
BeOS R5

◆ Replace() [2/2]

BString & BString::Replace ( const char *  replaceThis,
const char *  withThis,
int32  maxReplaceCount,
int32  fromOffset = 0 
)

Replace a number of occurrences of a string with another string.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
maxReplaceCountThe maximum number of occurrences that should be replaced.
fromOffsetThe offset in bytes to start looking for the string.
Returns
This method always returns *this.
See also
IReplace(const char*, const char*, int32, int32)
Since
BeOS R5

◆ ReplaceAll() [1/2]

BString & BString::ReplaceAll ( char  replaceThis,
char  withThis,
int32  fromOffset = 0 
)

Replace all occurrences of a character with another character.

Parameters
replaceThisThe character to replace.
withThisThe character to put in its place
fromOffsetThe offset in bytes to start looking for the character.
Returns
This method always returns *this.
See also
IReplaceAll(char, char, int32)
Since
BeOS R5

◆ ReplaceAll() [2/2]

BString & BString::ReplaceAll ( const char *  replaceThis,
const char *  withThis,
int32  fromOffset = 0 
)

Replace all occurrences of a string with another string.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
fromOffsetThe offset in bytes to start looking for the string.
Returns
This method always returns *this.
See also
IReplaceAll(const char*, const char*, int32)
Since
BeOS R5

◆ ReplaceAllChars()

BString & BString::ReplaceAllChars ( const char *  replaceThis,
const char *  withThis,
int32  fromCharOffset 
)

UTF-8 aware version of ReplaceAll(const char*, const char*, int32).

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
fromCharOffsetThe offset in UTF-8 characters to start looking for the string.
Returns
This method always returns *this.
See also
ReplaceAll(const char*, const char*, int32)
Since
Haiku R1

◆ ReplaceChars()

BString & BString::ReplaceChars ( const char *  replaceThis,
const char *  withThis,
int32  maxReplaceCount,
int32  fromCharOffset 
)

UTF-8 aware version of ReplaceAll(const char*, const char*, int32, int32).

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
maxReplaceCountThe maximum number of occurrences that should be replaced.
fromCharOffsetThe offset in UTF-8 characters to start looking for the string.
Returns
This method always returns *this.
See also
ReplaceAll(const char*, const char*, int32, int32)
Since
Haiku R1

◆ ReplaceCharsSet()

BString & BString::ReplaceCharsSet ( const char *  setOfChars,
const char *  with 
)

UTF-8 aware version of ReplaceSet(const char*, const char*)

Parameters
setOfCharsThe set of UTF-8 characters that need to be replaced.
withThe string to replace the occurrences with.
Returns
This method always returns *this.
Since
Haiku R1

◆ ReplaceFirst() [1/2]

BString & BString::ReplaceFirst ( char  replaceThis,
char  withThis 
)

Replace the first occurrence of a character with another character.

Parameters
replaceThisThe character to replace.
withThisThe character to put in its place.
Returns
This method always returns *this.
See also
IReplaceFirst(char, char)
Since
BeOS R5

◆ ReplaceFirst() [2/2]

BString & BString::ReplaceFirst ( const char *  replaceThis,
const char *  withThis 
)

Replace the first occurrence of a string with another string.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
Returns
This method always returns *this.
See also
IReplaceFirst(const char*, const char*)
Since
BeOS R5

◆ ReplaceLast() [1/2]

BString & BString::ReplaceLast ( char  replaceThis,
char  withThis 
)

Replace the last occurrence of a character with another character.

Parameters
replaceThisThe character to replace.
withThisThe character to put in its place
Returns
This method always returns *this.
See also
IReplaceLast(char, char)
Since
BeOS R5

◆ ReplaceLast() [2/2]

BString & BString::ReplaceLast ( const char *  replaceThis,
const char *  withThis 
)

Replace the last occurrence of a string with another string.

Parameters
replaceThisThe string to replace.
withThisThe string to put in its place
Returns
This method always returns *this.
See also
IReplaceLast(const char*, const char*)
Since
BeOS R5

◆ ReplaceSet() [1/2]

BString & BString::ReplaceSet ( const char *  setOfBytes,
char  with 
)

Replaces characters that are in a certain set with a chosen character.

Parameters
setOfBytesThe set of characters that need to be replaced.
withThe character to replace the occurrences with.
Returns
This method always returns *this.
Since
BeOS R5

◆ ReplaceSet() [2/2]

BString & BString::ReplaceSet ( const char *  setOfBytes,
const char *  with 
)

Replaces characters that are in a certain set with a chosen string.

Parameters
setOfBytesThe set of chars that need to be replaced.
withThe string to replace the occurrences with.
Returns
This method always returns *this.
Since
BeOS R5

◆ ScanWithFormat()

int BString::ScanWithFormat ( const char *  format,
  ... 
)

Parse a formatted string and save elements to variables ala scanf().

Parameters
formatThe format string to use.
...The parameters that you want to store the parsed data into.
Returns
This method returns the number of items that were parsed.
Since
Haiku R1

◆ ScanWithFormatVarArgs()

int BString::ScanWithFormatVarArgs ( const char *  format,
va_list  args 
)

Parse a formatted string and save elements to variables ala scanf().

Parameters
formatThe format string to use.
argsThe parameters that you want to store the parsed data into.
Returns
This method returns the number of items that were parsed.
Since
Haiku R1

◆ SetByteAt()

BString & BString::SetByteAt ( int32  pos,
char  to 
)

Set a byte at position pos to character to.

Parameters
posThe index of the byte to replace.
toThe new value that should replace the previous byte.
Returns
This method always returns *this.
Since
Haiku R1

◆ SetTo() [1/5]

BString & BString::SetTo ( char  c,
int32  count 
)

Re-initialize the object to a string composed of a character you specify.

This method lets you specify the length of a string and what character you want the string to contain repeatedly.

Parameters
cThe character you want to initialize the BString.
countThe length of the string.
Returns
The function always returns *this.
See also
operator=(char c)
Since
BeOS R5

◆ SetTo() [2/5]

BString & BString::SetTo ( const BString from)

Re-initialize the BString to a copy of the data of a BString.

Parameters
fromThe string data to re-initialize the BString to.
Returns
The function always returns *this.
See also
SetTo(const BString&, int32)
Adopt(BString&)
Since
BeOS R5

◆ SetTo() [3/5]

BString & BString::SetTo ( const BString string,
int32  maxLength 
)

Re-initialize the string to a copy of the given BString object.

Parameters
stringThe string data to re-initialize the BString to.
maxLengthMaximum number of characters (bytes) to copy.
Returns
The function always returns *this.
See also
operator=(const BString&)
Adopt(BString&, int32)
Since
BeOS R5

◆ SetTo() [4/5]

BString & BString::SetTo ( const char *  str)
inline

Re-initialize the BString to a copy of the data of a string.

This method calls operator=(const char*).

Parameters
strThe string data to re-initialize the BString to.
Returns
This method always returns *this.
See also
SetTo(const char*, int32)
Since
BeOS R5

References operator=().

◆ SetTo() [5/5]

BString & BString::SetTo ( const char *  str,
int32  maxLength 
)

Re-initialize the BString to a copy of the data of a string.

Parameters
strThe string data to re-initialize the BString to.
maxLengthMaximum number of characters (bytes) to copy.
Returns
This method always returns *this.
See also
operator=(const char*)
Since
BeOS R5

◆ SetToChars() [1/2]

BString & BString::SetToChars ( const BString string,
int32  charCount 
)

UTF-8 aware version of SetTo(BString&, int32)

Parameters
stringThe string to copy.
charCountThe number of UTF-8 characters to copy.
See also
SetTo(BString&, int32)
Returns
This method always returns *this.
Since
Haiku R1

◆ SetToChars() [2/2]

BString & BString::SetToChars ( const char *  string,
int32  charCount 
)

UTF-8 aware version of SetTo(const char*, int32)

Parameters
stringThe string to copy.
charCountThe number of UTF-8 characters to copy.
See also
SetTo(const char*, int32)
Since
Haiku R1

◆ SetToFormat()

BString & BString::SetToFormat ( const char *  format,
  ... 
)

Sets the string to a formatted string ala sprintf().

Parameters
formatThe format string to use.
...The rest of the parameters that are filled into format.
Returns
This method always returns *this.
Since
Haiku R1

◆ SetToFormatVarArgs()

BString & BString::SetToFormatVarArgs ( const char *  format,
va_list  args 
)

Sets the string to a formatted string ala sprintf().

Parameters
formatThe format string to use.
argsThe rest of the parameters that are filled into format.
Returns
This method always returns *this.
Since
Haiku R1

◆ Split()

bool BString::Split ( const char *  separator,
bool  noEmptyStrings,
BStringList _list 
) const

Split the string by the separator chars into _list.

Parameters
separatorThe list of separator characters to split on.
noEmptyStringsIf true, do not add empty strings to _list.
_listThe BStringList to add the strings into.
Since
Haiku R1

◆ StartsWith() [1/3]

bool BString::StartsWith ( const BString string) const

Returns whether or not the BString starts with string.

Parameters
stringThe string to search for.
Returns
true if the BString started with string, false otherwise.
Since
Haiku R1

◆ StartsWith() [2/3]

bool BString::StartsWith ( const char *  string) const

Returns whether or not the BString starts with string.

Parameters
stringThe string to search for.
Returns
true if the BString started with string, false otherwise.
Since
Haiku R1

◆ StartsWith() [3/3]

bool BString::StartsWith ( const char *  string,
int32  length 
) const

Returns whether or not the BString starts with length characters of string.

Parameters
stringThe string to search for.
lengthThe number of characters (bytes) of string to search for.
Returns
true if the BString started with length characters of string, false otherwise.
Since
Haiku R1

◆ String()

const char * BString::String ( ) const
inline

Return a pointer to the object string, NUL terminated.

The pointer to the object string is guaranteed to be NUL terminated. You can't modify or free the pointer. Once the BString object is deleted, the pointer becomes invalid.

If you want to manipulate the internal string of the object directly, have a look at LockBuffer().

Returns
A pointer to the object string.
Since
BeOS R5

Referenced by Append(), HashValue(), operator!=(), operator+=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ ToLower()

BString & BString::ToLower ( )

Convert each of the characters in the BString to lowercase.

Returns
This method always returns *this.
Since
BeOS R5

◆ ToUpper()

BString & BString::ToUpper ( )

Convert each of the characters in the BString to uppercase.

Returns
This method always returns *this.
Since
BeOS R5

◆ Trim()

BString & BString::Trim ( )

Removes spaces from the beginning and end of the string.

The definition of a space is set by the isspace() function.

Returns
This method always returns *this.
Since
Haiku R1

◆ Truncate()

BString & BString::Truncate ( int32  newLength,
bool  lazy = true 
)

Truncate the string to the new length.

Parameters
newLengthThe new length of the string in bytes.
lazyIf true, the memory-optimization is postponed until later.
Returns
This method always returns *this.
Since
BeOS R5

◆ TruncateChars()

BString & BString::TruncateChars ( int32  newCharCount,
bool  lazy = true 
)

UTF-8 aware version of Truncate(int32, bool).

Parameters
newCharCountThe new length of the string in UTF-8 characters.
lazyIf true, the memory-optimization is postponed until later.
See also
Truncate(int32, bool)
Since
Haiku R1

◆ UnlockBuffer()

BString & BString::UnlockBuffer ( int32  length = -1)

Unlocks the buffer after you are done with low-level manipulation.

Parameters
lengthThe length in bytes to trim the string to in order to keep the internal buffer sane. If you don't pass a value in it, strlen() will be used to determine the length.
Returns
This method always returns *this.
Since
BeOS R5