company logo

String :: erase - Erase characters from String

The function removes iCount characters or code points from the string starting at position passed in iPosition , and returns a reference to the string.

When the specified position is not within the string or when iCount is 0, the function does nothing.

odaba::String s = "Montreal is nice";

s.erase(1,4);

// s == "Meal is nice"

s.erase(1,-1,"n"); // remove all occurences of "n"

// s == "Motreal is ice"

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

Implementation overview

Implementation details

  1. Remove number of characters from String
    odaba::String & String  :: erase ( int32 iPosition, int32 iCount )

    The function removes iCount characters or code points from the string, starting at position passed in iPosition , and returns a reference to the string.

    When the specified position is within the string, but iPosition + iCount is beyond the end of the string, the string is truncated at the specified position.

    When the specified position is not within the string, the function does nothing. When iCount is less than zero or iPosition is less than zero 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.

    • iCount - Number of items

      The value contains the number of items to be processed or stored in a collection.

  2. to list
  3. Remove number of occurences of a string
    odaba::String & String  :: erase ( int32 iPosition, int32 iCount, odaba::String &cString )

    The function removes iCount occurrences of cString from the string. When iCount is -1 or when iCount is greater than the number of string occurrences, all occurrences of cString starting at iPosition will be removed.

    • iPosition - Position in collection

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

    • iCount - Number of items

      The value contains the number of items to be processed or stored in a collection.

    • cString - Constant string object

      When iPosition exceeds the string length or when the string is empty, the the function returns -1 (lower).

  4. to list