Compañeros, buenas tardes:
¿Sabeis la función que reemplaza un valor dentro de una cadena de caracteres?
Tengo una DBF con el campo NOMBRE,C,40
pero necesito hacer un barrido y cambiar todas las "A" del campo NOMBRE por "C"
algo así como
remplezar(nombre,"A","C")
Mil gracias.
LORENZO.
reemplazar un valor en una cadena caracteres
-
- Posts: 392
- Joined: Wed Jul 31, 2013 1:14 pm
- Location: Maldonado - Uruguay
- Contact:
Re: reemplazar un valor en una cadena caracteres
Lorenzo, si usas harbour tienes que enlazar hbct.lib
La funcion es Charrepl()
te dejo debajo como funciona
Saludos
/*
* $Id: charrepl.txt 15102 2010-07-14 12:48:39Z vszakats $
*/
/* $DOC$
* $FUNCNAME$
* CHARREPL()
* $CATEGORY$
* CT3 string functions
* $ONELINER$
* Replacement of characters
* $SYNTAX$
* CHARREPL (<cSearchString>, <[@]cString>,
* <cReplaceString>, [<lMode>]) -> cString
* $ARGUMENTS$
* <cSearchString> is a string of characters that should be replaced
* <[@]cString> is the processed string
* <cReplaceString> is a string of characters that replace the one
* of <cSearchString>
* [<lMode>] sets the replacement method (see description)
* Default: .F.
* $RETURNS$
* <cString> the processed string
* $DESCRIPTION$
* The CHARREPL() function replaces certain characters in <cString>
* with others depending on the setting of <lMode>.
* If <lMode> is set to .F., the function takes the characters of
* <cSearchString> one after the other, searches for them in <cString>
* and, if successful, replaces them with the corresponding character
* of <cReplaceString>. Be aware that if the same characters occur
* in both <cSearchString> and <cReplaceString>, the character on a
* certain position in <cString> can be replaced multiple times.
* if <lMode> is set to .T., the function takes the characters in <cString>
* one after the other, searches for them in <cSearchString> and, if
* successful, replaces them with the corresponding character of
* <cReplaceString>. Note that no multiple replacements are possible
* in this mode.
* If <cReplaceString> is shorter than <cSearchString>, the last
* character of <cReplaceString> is used as corresponding character
* for the the "rest" of <cSearchString>.
* One can omit the return value by setting the CSETREF() switch to .T.,
* but then one must pass <cString> by reference to get the result.
* $EXAMPLES$
* ? charrepl ("1234", "1x2y3z", "abcd") // "axbycz"
* ? charrepl ("abcdefghij", "jhfdb", "1234567890") // "08642"
* ? charrepl ("abcdefghij", "jhfdb", "12345") // "55542"
* ? charrepl ("1234", "1234", "234A") // "AAAA"
* ? charrepl ("1234", "1234", "234A", .T.) // "234A"
* $TESTS$
* charrepl ("1234", "1x2y3z", "abcd") == "axbycz"
* charrepl ("abcdefghij", "jhfdb", "1234567890") == "08642"
* charrepl ("abcdefghij", "jhfdb", "12345") == "55542"
* charrepl ("1234", "1234", "234A") == "AAAA"
* charrepl ("1234", "1234", "234A", .T.) == "234A"
* $STATUS$
* Ready
* $COMPLIANCE$
* CHARREPL() is compatible with CT3's CHARREPL().
* $PLATFORMS$
* All
* $FILES$
* Source is charrepl.c, library is ct3.
* $SEEALSO$
* WORDREPL() POSREPL() RANGEREPL()
* CSETREF()
* $END$
*/
Ruben Dario Fernandez
La funcion es Charrepl()
te dejo debajo como funciona
Saludos
/*
* $Id: charrepl.txt 15102 2010-07-14 12:48:39Z vszakats $
*/
/* $DOC$
* $FUNCNAME$
* CHARREPL()
* $CATEGORY$
* CT3 string functions
* $ONELINER$
* Replacement of characters
* $SYNTAX$
* CHARREPL (<cSearchString>, <[@]cString>,
* <cReplaceString>, [<lMode>]) -> cString
* $ARGUMENTS$
* <cSearchString> is a string of characters that should be replaced
* <[@]cString> is the processed string
* <cReplaceString> is a string of characters that replace the one
* of <cSearchString>
* [<lMode>] sets the replacement method (see description)
* Default: .F.
* $RETURNS$
* <cString> the processed string
* $DESCRIPTION$
* The CHARREPL() function replaces certain characters in <cString>
* with others depending on the setting of <lMode>.
* If <lMode> is set to .F., the function takes the characters of
* <cSearchString> one after the other, searches for them in <cString>
* and, if successful, replaces them with the corresponding character
* of <cReplaceString>. Be aware that if the same characters occur
* in both <cSearchString> and <cReplaceString>, the character on a
* certain position in <cString> can be replaced multiple times.
* if <lMode> is set to .T., the function takes the characters in <cString>
* one after the other, searches for them in <cSearchString> and, if
* successful, replaces them with the corresponding character of
* <cReplaceString>. Note that no multiple replacements are possible
* in this mode.
* If <cReplaceString> is shorter than <cSearchString>, the last
* character of <cReplaceString> is used as corresponding character
* for the the "rest" of <cSearchString>.
* One can omit the return value by setting the CSETREF() switch to .T.,
* but then one must pass <cString> by reference to get the result.
* $EXAMPLES$
* ? charrepl ("1234", "1x2y3z", "abcd") // "axbycz"
* ? charrepl ("abcdefghij", "jhfdb", "1234567890") // "08642"
* ? charrepl ("abcdefghij", "jhfdb", "12345") // "55542"
* ? charrepl ("1234", "1234", "234A") // "AAAA"
* ? charrepl ("1234", "1234", "234A", .T.) // "234A"
* $TESTS$
* charrepl ("1234", "1x2y3z", "abcd") == "axbycz"
* charrepl ("abcdefghij", "jhfdb", "1234567890") == "08642"
* charrepl ("abcdefghij", "jhfdb", "12345") == "55542"
* charrepl ("1234", "1234", "234A") == "AAAA"
* charrepl ("1234", "1234", "234A", .T.) == "234A"
* $STATUS$
* Ready
* $COMPLIANCE$
* CHARREPL() is compatible with CT3's CHARREPL().
* $PLATFORMS$
* All
* $FILES$
* Source is charrepl.c, library is ct3.
* $SEEALSO$
* WORDREPL() POSREPL() RANGEREPL()
* CSETREF()
* $END$
*/
Ruben Dario Fernandez
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
Re: reemplazar un valor en una cadena caracteres
Gracias Ruben, pero utilizo xHarbour
-
- Posts: 392
- Joined: Wed Jul 31, 2013 1:14 pm
- Location: Maldonado - Uruguay
- Contact:
Re: reemplazar un valor en una cadena caracteres
Lorenzo, tambien esta en xHarbour.
Saludos
Ruben Dario Fernandez
Saludos
Ruben Dario Fernandez
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
- Willi Quintana
- Posts: 859
- Joined: Sun Oct 09, 2005 10:41 pm
- Location: Cusco - Perú
- Contact:
Re: reemplazar un valor en una cadena caracteres
Holas.... revisen esto:
cXx := "AHAHAHSHAHAHAH"
cXx := STRTRAN(cXx, "A", "C") // REEMPLAZA LA "A" POR LA "C"
? cXx -> CHCHCHSHCHCHCH
sALU2
cXx := "AHAHAHSHAHAHAH"
cXx := STRTRAN(cXx, "A", "C") // REEMPLAZA LA "A" POR LA "C"
? cXx -> CHCHCHSHCHCHCH
sALU2
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: reemplazar un valor en una cadena caracteres
Como dice Willi, StrTran()