Page 1 of 2

Reemplazar cadena dentro de un nombre

Posted: Fri Oct 14, 2022 4:25 pm
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

Re: Reemplazar cadena dentro de un nombre

Posted: Sat Oct 15, 2022 2:31 am
by andyglezl
Quizá...

nombreCfdi4 := hb_StrReplace( nombreCliente, { 'S.A.' => '', 'C.V.' => '', 'A.C.' => '' } )

Re: Reemplazar cadena dentro de un nombre

Posted: Sun Oct 16, 2022 6:48 pm
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!!!

Re: Reemplazar cadena dentro de un nombre

Posted: Mon Oct 17, 2022 9:41 am
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

Re: Reemplazar cadena dentro de un nombre

Posted: Mon Oct 17, 2022 1:43 pm
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

Re: Reemplazar cadena dentro de un nombre

Posted: Mon Oct 17, 2022 5:26 pm
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

Re: Reemplazar cadena dentro de un nombre

Posted: Tue Oct 18, 2022 12:32 am
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

Re: Reemplazar cadena dentro de un nombre

Posted: Tue Oct 18, 2022 11:51 pm
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.

Re: Reemplazar cadena dentro de un nombre

Posted: Wed Oct 19, 2022 2:43 pm
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

Re: Reemplazar cadena dentro de un nombre

Posted: Thu Oct 20, 2022 12:06 am
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 )