Reemplazar cadena dentro de un nombre

HMG en Español

Moderator: Rathinagiri

jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Reemplazar cadena dentro de un nombre

Post by jparada »

Hola,
Estoy intentar realizar un reemplazo de texto dentro de otro texto, que para este caso, son los nombres de clientes:

Lo intento de esta forma:

nombreCfdi4 := ;
hb_StrReplace( nombreCliente, { ;
"S.A. DE C.V." => "", ;
"A.C." => "", ;
"S.A.DE C.V." => "", ;
"S.A DE C.V." => "", ;
".S.A.DE C.V." => "", ;

Pero esto no está funcionando como yo espero, es decir, no toma la cadena exacta a reemplazar, hb_StrReplace es como si funcionara indicando si la cadena xxx está contenida en el nombre, entonces eso hace que el procedimiento no funcione como se espera.

También intenté realizarlo con el operador $, es decir:

if "S.A.DE C.V." $ nombreCliente
StrTran( nombreCliente, "S.A.DE C.V.", "" )
endif

pero tampoco funciona.

Alguna idea de cómo le pudiera dar la vuelta.

Saludos,
Javier
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Reemplazar cadena dentro de un nombre

Post by andyglezl »

Quizá...

nombreCfdi4 := hb_StrReplace( nombreCliente, { 'S.A.' => '', 'C.V.' => '', 'A.C.' => '' } )
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Reemplazar cadena dentro de un nombre

Post by SALINETAS24 »

jparada wrote: Fri Oct 14, 2022 4:25 pm Hola,
Estoy intentar realizar un reemplazo de texto dentro de otro texto, que para este caso, son los nombres de clientes:

Lo intento de esta forma:

nombreCfdi4 := ;
hb_StrReplace( nombreCliente, { ;
"S.A. DE C.V." => "", ;
"A.C." => "", ;
"S.A.DE C.V." => "", ;
"S.A DE C.V." => "", ;
".S.A.DE C.V." => "", ;

Pero esto no está funcionando como yo espero, .....

Saludos,
Javier
Hola Javier.., a mi de esta forma me funciona.

Code: Select all

		nombreCliente="JOSE Manuel"
		msgbox(nombreCliente)
		nombreCliente:=Hb_StrReplace(nombreCliente,{"JOSE"=> "PACO"}) 
		msgbox(nombreCliente)
Saludos y una ronda de cervecita fresquita para todos!!!
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Reemplazar cadena dentro de un nombre

Post by franco »

Try, if table is Cliente and field is name

Code: Select all

if  "S.A.DE C.V." $ Cliente->name
Cliente->name:=Hb_StrReplace(Cliente->name,{"S.A.DE C.V."=>space(0)})
endif
All The Best,
Franco
Canada
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: Reemplazar cadena dentro de un nombre

Post by jparada »

Es lo que comento, hb_StrReplace al parecer funciona de la misma forma que $, es decir no buscan la coincidencia exacta, funcionan buscando que contengan la cadena a buscar, y si yo pongo S.A. y S.A. DE C.V. encuentra en ambas búsquedas S.A., necesito algo para buscar el texto exacto y reemplazar, requiero buscar aproximadamente 50 valores, algo así:

"S.A. DE C.V." => "", ;
"A.C." => "", ;
"S.A.DE C.V." => "", ;
"S.A DE C.V." => "", ;
".S.A.DE C.V." => "", ;
"S. A. S. DE C.V." => "", ;
"S.A. DE C.V" => "", ;
"S DE R.L. DE C.V" => "", ;
"S.A.P.I. DE C.V." => "", ;
"S DE R.L. DE C.V." => "", ;
"S.A DE CV" => "", ;
"SA. DE CV." => "", ;

Saludos,
Javier
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Reemplazar cadena dentro de un nombre

Post by SALINETAS24 »

jparada wrote: Mon Oct 17, 2022 1:43 pm Es lo que comento, hb_StrReplace al parecer funciona de la misma forma que $, es decir no buscan la coincidencia exacta.....,
Saludos,
Javier

Hola, has probado ..

SET EXACT ON

SL2
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Reemplazar cadena dentro de un nombre

Post by franco »

I have tested this and it works.
In a big file the msgbox() will make it very slow, but you can see the results. A browse at the end may be nicer.
Am not sure about nombreCfdi4. if I use cliente->name it replaces the name field. I think if you have a field nombreCfdi4
it will replace it.

Code: Select all

set exact on
use cliente                    // this works for replacing part of field
go top
do while .not. eof()
msgbox(name+nombreCfdi4)
nombreCfdi4:=Hb_StrReplace(cliente->name,{"S DE"=>"", "P."=>"",;
	"S.A. DE C.V." => "", ;
	"A.C." => "", ;
	"S.A.DE C.V." => "", ;
	"S.A DE C.V." => "", ;
	".S.A.DE C.V." => "", ;
	"S. A. S. DE C.V." => "", ;
	"S.A. DE C.V" => "", ;
	"S DE R.L. DE C.V" => "", ;
	"S.A.P.I. DE C.V." => "", ;
	"S DE R.L. DE C.V." => "", ;
	"S.A DE CV" => "", ;
	"SA. DE CV." => ""})                       //   And many more as you need.

msgbox(name+nombreCfdi4)
SKIP
LOOP
ENDDO
use
SET EXACT OFF
All The Best,
Franco
Canada
franco
Posts: 889
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Reemplazar cadena dentro de un nombre

Post by franco »

I have done more tests on the above code and it amazingly takes out any of the above values so if
name starts out TOMP.S.A. DE C.V.SA
nombreCfdi4 will be TOMSA it will take out any of the above complete values and not TOM or SA because they are not in the values list.
Thanks to Andy, I started from his code.
I hope this is what you where looking for, and I have learned a lot working on this.
I do a lot of importing text files to tables and this will work great for removing unwanted values from an appended text line.
All The Best,
Franco
Canada
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: Reemplazar cadena dentro de un nombre

Post by jparada »

Hi,

In my case it doesn't work either even with SET EXACT ON, BTW, the description says
SET EXACT determines how two character strings are compared using the relational operators (=, >, <, =>, =<).

So I really don't know if SET EXACT helps in this case.

Code: Select all

nombreCfdi4 := ;
          hb_StrReplace( nombrecliente, { ;
         ", SA DE CV." => "", ;
         "SA. DE CV." => "", ;
         "S.A DE CV" => "", ;
         "S.A.DE C.V." => "", ;
         "S.A DE C.V." => "", ;
         ".S.A.DE C.V." => "", ;
         "S.A. DE C.V." => "", ;
         ",S.A. DE C.V." => "", ;         
         ", S.A. DE C.V." => "", ;
         "S.A DE C.V" => "", ;
         "S.A. DE C.V" => "", ;
         "SA DE CV" => "", ;
         ",SA.DE CV" => "",  ;
         "SA DE CV." => "", ;
         ", S.A DE C.V" => "", ;
         "S.A DE C.V." => "", ;         
         ", S.A. DE.C.V" => "", ;         
         "S.A. DE C" => "", ;
         "S.A DE C" => "", ;
         "S.A. DE" => "", ;
What I realize at least in my case influences the order in which I define the characters to replace, the order definitely changes if it works or not, so if I change the order, it works a little better, but not 100% appropriately.

I don't understand if I am not using the correct functions, so my first question was about what functions to use to find the exact match of the characters to search, even also try with AT, but it doesn't work either, in short I think I'll have to leave this process, with the results obtained and pass the work of validation to the end user, anyway, if new ideas arise I appreciate your help.

Regards,
Javier
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Reemplazar cadena dentro de un nombre

Post by andyglezl »

Hola
Esto funciona...

Code: Select all

	LOCAL Elemento, aResult
	aDatoABuscar := { ", SA DE CV.", ;
					 "SA. DE CV.", ;
					 "S.A DE CV", ;
					 "S.A.DE C.V.", ;
					 "S.A DE C.V.", ;
					 ".S.A.DE C.V.", ;
					 "S.A. DE C.V.", ;
					 ",S.A. DE C.V.", ;         
					 ", S.A. DE C.V.", ;
					 "S.A DE C.V", ;
					 "S.A. DE C.V", ;
					 "SA DE CV", ;
					 ",SA.DE CV",  ;
					 "SA DE CV.", ;
					 ", S.A DE C.V", ;
					 "S.A DE C.V.", ;         
					 ", S.A. DE.C.V", ;         
					 "S.A. DE C", ;
					 "S.A DE C", ;
					 "S.A. DE" }
					
	aResult := ARRAY( HMG_LEN( aDatoABuscar ) )
	For i1 = 1 TO HMG_LEN( aDatoABuscar )
		aResult[ i1 ] := hb_StrReplace( aDatoABuscar[ i1 ], ;
			{ ' ' => '', '.' => '', ',' => '', 'S' => '', 'A' => '', 'C' => '', 'V' => '', 'DE' => '' } )
	Next
	
	MsgDebug( aResult )
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply