Clipper On Line • Ver Tópico - Função nova muito util, HB_STRXCHG()

Função nova muito util, HB_STRXCHG()

Projeto Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

 

Função nova muito util, HB_STRXCHG()

Mensagempor Itamar M. Lins Jr. » 15 Fev 2013 21:45

Ola!
2013-02-15 01:53 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
  * harbour/include/harbour.hbx
  * harbour/src/rtl/Makefile
  + harbour/src/rtl/strxchg.c
    + added new PRG function:
         hb_strXChg( <cString>, <cSource> | <acSource>, ;
                                <cDest> | <acDest> ] ) -> <cResult>
      This function allows to easy replace different substrings in
      given string.
      If 2-nd is string then each character in <cString> which exists
      in <cSource> at <n> position is replaced by corresponding character
      at <n> position in <cDest> or string from <acDest>[ <n> ]
      If 2-nd parameter is array then each <cString> substring which exists
      in <acSource> at <n> position is replaced by corresponding character
      at <n> position in <cDest> or string from <acDest>[ <n> ].
      If <n> is longer then LEN() of <cDest> or <acDest> then given
      character/substring is removed from result.
      This function should help in code which wrongly uses repeated
      StrTran() calls all regex which can change also substituted values.
      Examples:
         // encode XML value
         cXmlText := hb_strXChg( cText, "<>&", { "&lt;", "&gt;", "&amp;" } )
         // now decode it to raw text
         cText := hb_strXChg( cXmlText, { "&lt;", "&gt;", "&amp;" }, "<>&" )
         // strip all digits from string
         cNoDigit := hb_strXChg( cText, "0123456789" )
         // extract all digits from string
         cDigits := hb_strXChg( cText, cNoDigit )
         // convert chosen letters to upper case
         ? hb_strXChg( "hello world, "hlwd", "HLWD" )

2013-02-15 12:14 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
  * harbour/src/rtl/strxchg.c
    + added support for using hash arrays as replace pairs in second
      argument of hb_strXChg() - hash arrays are accepted if 3-rd parameter
      is ommitted or is NIL. Now this alternative syntax:
         hb_strXChg( <cString>, <hChanges> ) -> <cResult>
      is also supported, i.e.:
         cData := hb_strXChg( cSource, { "{LI}" => cLIValue, ;
                                         "{FI}" => cFIValue } )
      Please remember that single hash layer is much lighter data type
      then array of subarrays because it needs only one GC item when
      each subarray is new GC item.

Saudações,
Itamar M. Lins Jr.
Avatar de usuário

Itamar M. Lins Jr.
Colaborador

Colaborador
 
Mensagens: 6958
Data de registro: 30 Mai 2007 11:31
Cidade/Estado: Ilheus Bahia
Curtiu: 312 vezes
Mens.Curtidas: 508 vezes



Retornar para Harbour

Quem está online

Usuários vendo este fórum: Nenhum usuário registrado online e 10 visitantes


Ola Amigo, espero que meu site e forum tem lhe beneficiado, com exemplos e dicas de programacao.
Entao divulgue o link da Doacao abaixo para seus amigos e redes sociais ou faça uma doacao para o site forum...
MUITO OBRIGADO PELA SUA DOACAO!
Faça uma doação para o forum
cron
v
Olá visitante, seja bem-vindo ao Fórum Clipper On Line!
Efetue o seu login ou faça o seu Registro