xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

AtRepl()

Searches and replaces a substring within a string.

Syntax

AtRepl( <cSearch> , ;
        <cString>  , ;
        <cReplace> , ;
        [<nCount>] , ;
        [<lOneOnly>] ) --> cResult

Arguments

<cSearch>
This is a character string to search in <cString>.
<cString>
This is a character string to find <cSearch> in.
<cReplace>
This is a character string that replaces <cSearch> in <cString>.
<nCount>
A numeric value indicating the number of occurrences of finding <cSearch> in <cString> before the function returns. It defaults to the last occurrence.
<lOneOnly>
This parameter defaults to .F. (false) so that only the <nCount>th occurrence of <cSearch> is replaced. Passing .T. (true) instructs the function to replace all occurrences up to and including the <nCount>th occurrence.

Return

The function returns the modified string.

Info

See also:AtNum(), AtAdjust(), CSetAtMuPa(), SetAtLike()
Category: CT:String manipulation , Character functions
Source:ct\atrepl.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates return vales of AtRepl()

   PROCEDURE Main
      LOCAL cString := "ABC_ABC_ABC"

      ? AtRepl( "_", cString, "x" )          // result: ABCxABCxABC
      ? AtRepl( "_", cString, "x",, .T. )    // result: ABC_ABCxABC

      ? AtRepl( "AB", cString, "1", 2 )      // result: 1C_1C_ABC
      ? AtRepl( "AB", cString, "1", 2, .T. ) // result: ABC_1C_ABC
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe