Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

void PString::Replace ( const PString target,
const PString subs,
BOOL  all = FALSE,
PINDEX  offset = 0 
) [inherited]

Locate the substring within the string and replace it with the specifed substring. The search will begin at the character offset provided.

If offset# is beyond the length of the string, then the function will do nothing.

The matching will be for identical character or string. If a search ignoring case is required then the string should be converted to a PCaselessString# before the search is made.

Parameters:
target  Text to be removed.
subs  String to be inserted into the gaps created
all  Replace all occurrences of target text.
offset  Offset into string to begin search.

Definition at line 2088 of file contain.cxx.

References PString::Find(), PString::GetLength(), PString::MakeUnique(), and PString::Splice().

{
  if (offset < 0)
    return;
    
  MakeUnique();

  PINDEX tlen = target.GetLength();
  PINDEX slen = subs.GetLength();
  do {
    PINDEX pos = Find(target, offset);
    if (pos == P_MAX_INDEX)
      return;
    Splice(subs, pos, tlen);
    offset = pos + slen;
  } while (all);
}


Generated by  Doxygen 1.6.0   Back to index