company logo

String :: replace - Replace specified string or text range by new string

The function replaces the string sOld with the string sNew and returns a reference to this string. .

The coding type of the result depends on the string coding type of the calling string. When encoding types of the strings differ, copies of strings passed in sOld and/or sNeware recoded to the encoding type of the calling string before performing the operation..

odaba::String str = "odaba Database";

str.replace("da","?",false);

// str == "o?ba ?tabase"

odaba::String str = "xxxxxx";

str.replace("xx","x");

// str == "xxx"

Return value:  String object ( odaba::String & )

Implementation overview

Implementation details

  1. Replace all string occurences case sensitive
    odaba::String & String  :: replace ( odaba::String &sOld, odaba::String &sNew )

    The function replaces all occurrence of the string value passed in sOld with the string value passed in sNew and returns a reference to this string. The replacement text is not rescanned after it is inserted, i.e. replacing does not work recursively. The search is case sensitive.

    When sOld is empty, the function throws an exception.

    • sOld - Old string value
    • sNew - New string value
  2. to list
  3. Replace all string occurences
    odaba::String & String  :: replace ( odaba::String &sOld, odaba::String &sNew, bool bCaseSensitive )

    The function replaces all occurrence of the string value passed in sOld with the string value passed in sNew and returns a reference to this string. The replacement text is not rescanned after it is inserted, i.e. replacing does not work recursively. When bCaseSensitive is true (default), the search is case sensitive; otherwise the search is case insensitive.

    When sOld is empty, the function throws an exception.

    • sOld - Old string value
    • sNew - New string value
    • bCaseSensitive - Case sensitive option

      The option indicates case sensitive data in text (true)

  4. to list
  5. Replace first occurence
    odaba::String & String  :: replace ( int32 iPosition, odaba::String &sOld, odaba::String &sNew, bool bCaseSensitive )

    The function replaces the first occurrence of the string sOld with the string value passed in sOld with the string value passed in sNew beginning at position passed in iPosition (units). When the specified position exceeds the string length, nothing is replaced.

    When bCaseSensitive is true (default), the search is case sensitive; otherwise the search is case insensitive.

    When iPosition is negative or sOld is empty, the function throws an exception.

    • iPosition - Position in collection

      The position of an element in a collection is beginning with 0 for the first element.

    • sOld - Old string value
    • sNew - New string value
    • bCaseSensitive - Case sensitive option

      The option indicates case sensitive data in text (true)

  6. to list