STRTRAN case

STRTRAN case

Postby Marc Vanzegbroeck » Tue Jan 28, 2020 11:49 am

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  Expand view  RUN
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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: STRTRAN case

Postby karinha » Tue Jan 28, 2020 12:10 pm

Code: Select all  Expand view  RUN

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


Seealso

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

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7835
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: STRTRAN case

Postby MarcoBoschi » Tue Jan 28, 2020 12:11 pm

Marc,
can you give us an example?
bye
User avatar
MarcoBoschi
 
Posts: 1066
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: STRTRAN case

Postby Marc Vanzegbroeck » Tue Jan 28, 2020 12:19 pm

Marco,

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

Code: Select all  Expand view  RUN
<property name="PointRefPointName">MarcTag001</property>


After the replace the result should be
Code: Select all  Expand view  RUN
<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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: STRTRAN case

Postby rhlawek » Tue Jan 28, 2020 5:01 pm

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
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: STRTRAN case

Postby Marcelo Via Giglio » Tue Jan 28, 2020 5:34 pm

Hola,

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

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1065
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: STRTRAN case

Postby Marc Vanzegbroeck » Wed Jan 29, 2020 7:09 am

Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: STRTRAN case

Postby nageswaragunupudi » Wed Jan 29, 2020 8:34 pm

Code: Select all  Expand view  RUN
  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  Expand view  RUN
  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
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: STRTRAN case

Postby Marc Vanzegbroeck » Wed Jan 29, 2020 8:41 pm

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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: STRTRAN case

Postby nageswaragunupudi » Wed Jan 29, 2020 8:43 pm

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
User avatar
nageswaragunupudi
 
Posts: 10653
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: STRTRAN case

Postby Marc Vanzegbroeck » Wed Jan 29, 2020 8:48 pm

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
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: STRTRAN case

Postby reinaldocrespo » Wed Jan 29, 2020 9:34 pm

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  Expand view  RUN

#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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 101 guests