STRTRAN case

Post Reply
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

STRTRAN case

Post by Marc Vanzegbroeck »

Hi,

I have a text with lower and upper case charachters.
I want to to a replace op a text with another text.
The problem is that I don't know this text is upper or lower case.
How can I replace only that text,and leave the other case normal?
If I do

Code: Select all

result = strtran(upper(text),alltrim(upper(oldtext)),alltrim(upper(newtext)))
than everything is upper-case.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: STRTRAN case

Post by karinha »

Code: Select all

   ? ISUPPER( "Abcde" )    // .T.
   ? ISUPPER( "abcde" )    // .F.
 
Seealso

ISALPHA(), ISLOWER(), ISDIGIT(), LOWER(), UPPER()

Regards.
João Santos - São Paulo - Brasil
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: STRTRAN case

Post by MarcoBoschi »

Marc,
can you give us an example?
bye
Marco Boschi
info@marcoboschi.it
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: STRTRAN case

Post by Marc Vanzegbroeck »

Marco,

In this example I wat to change the text 'MARCTAG001' with 'PI101'
I don't know the case of 'MarcTag001'

Code: Select all

<property name="PointRefPointName">MarcTag001</property>
After the replace the result should be

Code: Select all

<property name="PointRefPointName">PI101</property>
BTW : I'ts not always between 'PointRefPointName', so I can't search fo that.
Last edited by Marc Vanzegbroeck on Tue Jan 28, 2020 5:33 pm, edited 1 time in total.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
rhlawek
Posts: 165
Joined: Sun Jul 22, 2012 7:01 pm

Re: STRTRAN case

Post by rhlawek »

Marc,

I suggest going here and reading about the hb_StrReplace() function. Much more flexible than StrTran.

https://github.com/Petewg/harbour-core/wiki/hb_S
Marcelo Via Giglio
Posts: 1033
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: STRTRAN case

Post by Marcelo Via Giglio »

Hola,

can be usefull to see this page https://github.com/Petewg/harbour-core/ ... xpressions too

saludos

Marcelo
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: STRTRAN case

Post by Marc Vanzegbroeck »

I was hoping on a extra parameter like in foxpro :D
https://books.google.be/books?id=gdPcwW ... se&f=false
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: STRTRAN case

Post by nageswaragunupudi »

Code: Select all

   local cText    := "This is HIS List"
   local cSearch  := "IS"
   local cReplace := "99"

   FW_At( cSearch, @cText, nil, nil, .f., .f., nil, cReplace, .t. )
   ? cText  // -> Th99 99 H99 L99t"
   
//   Syntax: FW_AT( acSub, @cString, nStart, nEnd, lWholeWord, lSkipQuotes, @cFound, cReplace, lAll ) // FWH1905
 
Another approach

Code: Select all

   local cText    := "This is HIS List"
   local cSearch  := "IS"
   local cReplace := "99"
   local nAt

   do while ( nAt := AT( cSearch, UPPER( cText ) ) ) > 0
      cText  := STUFF( cText, nAt, Len( cSearch ), cReplace )
   enddo

   ? cText //-> "Th99 99 H99 L99t"
 
Regards

G. N. Rao.
Hyderabad, India
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: STRTRAN case

Post by Marc Vanzegbroeck »

Thank you Rao,

I think I have to upgrade my FW... :oops:

Or I can use you other approach :D :D
Last edited by Marc Vanzegbroeck on Wed Jan 29, 2020 8:45 pm, edited 1 time in total.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: STRTRAN case

Post by nageswaragunupudi »

It is good to upgrade but in the same post, I have also given a solution for older versions.
Regards

G. N. Rao.
Hyderabad, India
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: STRTRAN case

Post by Marc Vanzegbroeck »

Thank you Rao,

I saw it after I posted my replay :D
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: STRTRAN case

Post by reinaldocrespo »

Hello everyone;

When searching for text, I find that nothing is as good as using regular expressions. hb_RegExAll() --my favorite, will search for a regular expression on any string and return a double dimensioned array with all matches. Once you do know the matches you could potentially use StrTran to replace with desired text, or you could use hb_RegExReplace() to do so from the very beginning.

To build the regular expression you cal always look at any regular expression tutorial and tester online. That's what I do every time I need to build a regular expression for anything.

For example:

Code: Select all

#define _SEARCH ">[A-Z]*[a-z]*[A-Z]*[a-z]*[0-9]*<"

LOCAL cYourString := '<property name="PointRefPointName">MarcTag001</property>'
LOCAL cReplaceWith := '>PI101<'

HB_RegExReplace( _SEARCH, cYourString, cReplaceWith )

 
Hope that helps,


Reinaldo.
Post Reply