FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour At() and Rat() return the same value on a character string
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
At() and Rat() return the same value on a character string
Posted: Wed May 15, 2024 08:51 PM
To All ( enrico )

I an using fivewin 2404 and xHarbour build 20240413 .. This code returns the same value
Code (fw): Select all Collapse
xValue := "Amy Halady"

cName := alltrim( xValue )
msginfo( cName )        // Amy Halady

nLen := len( cName )
msginfo( nLen )             //10

nAt := at(" ", cName )
msginfo( nAT )              // 4

nRat := rat( " ",cName )
msginfo( nRat )             // 4
Rat() is supposed to count backwards and the above rat() function returns 4 but should return 6 .. Hopefully someone can compile this simple code and verify my results

Thanks
Rick Lipkin
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: At() and Rat() return the same value on a character string
Posted: Wed May 15, 2024 09:10 PM

No, 4 is the correct result. The difference between AT() and RAT() is that RAT() search from right to left but the position is always counted from left. Anyway, Harbour shows the same result as xHarbour.

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: At() and Rat() return the same value on a character string
Posted: Thu May 16, 2024 02:29 PM

Enrico

cName :- "Amy Halady"

What I expect nAt := at( " ", cName ) scans forward from left to right so starting with "Amy " so space is the 4th character

                 nRat   := rat( " ", cName ) scans backwards from right to left starting with " Hadley" so the space is the 6th character

nLen := len( cName ) = 10

What am I missing ... ?? What I am trying to do is split the name above into First Name and Last name .. using the space(s) as the delimiter between the first name and the last name but sometimes the space may not be always be just one space, it may be two spaces like "Amy Hadley" so now I need to know counting backwards where the end of the space may be .. So in order to get the correct results I need to know where the space starts and where the space ends, hence the use of the At() and Rat() function ...

Is there a better way ... of knowing where the space starts and where the space ends in a string ??

Thanks

Rick

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: At() and Rat() return the same value on a character string
Posted: Thu May 16, 2024 02:36 PM
Rick Lipkin wrote:Enrico

cName :- "Amy Halady"

What I expect nAt := at( " ", cName ) scans forward from left to right so starting with "Amy " so space is the 4th character
nRat := rat( " ", cName ) scans backwards from right to left starting with " Hadley" so the space is the 6th character
There is only one space in the string "Amy Halady", so you get the same result from AT() and RAT(). Try with the string "Enrico Maria Giordano" and you will get 7 with AT() and 13 with RAT().
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: At() and Rat() return the same value on a character string
Posted: Thu May 16, 2024 02:50 PM
Rick
Podrias hacer
Code (fw): Select all Collapse
nPos := Len(cName)- rAt( " ",cName)
De esta manera obtienes cuantos caracateres hay por detras del caracter buscado

Continue the discussion