Página 1 de 1

At() e RAt()

Enviado: 13 Out 2016 16:11
por Itamar M. Lins Jr.
Ola!

Código: Selecionar todos

function main 
local nA:=0.01, nB:=0.001, cA, cB
cA := transform(nA,"@L")
? at(".",cA) //return 11
cB := transform(nB,"@L")
? rat(".",cB) //return 11
Não deveria ser 4 em rat() ?
Como eu pego da direita para esquerda ?

Saudações,
Itamar M. Lins Jr.

At() e RAt()

Enviado: 13 Out 2016 16:36
por Jairo Maia
Interessante, mas veja isso:

Código: Selecionar todos

function main
local nA:=0.01, nB:=0.001, cA, cB

Clear Screen

cA := transform(nA,"@L")
? cA
? at(".",cA) //return 11
?
cB := transform(nB,"@L")
? cB
? rat(".",cB) //return 11
?
nPosiA := SubStr( cA, Rat( ".", cA ) )
? nPosiA
?
nPosiB := SubStr( cB, Rat( ".", cB ) )
? nPosiB
?
?
nPosiA := SubStr( cA, Rat( ".", cA ) + 1 )
? nPosiA
?
nPosiB := SubStr( cB, Rat( ".", cB ) + 1 )
? nPosiB
?

At() e RAt()

Enviado: 13 Out 2016 16:48
por Itamar M. Lins Jr.
Ola!
Com at ai no seu código tem o mesmo resultado.
Mas o RAt() não retorna da direita para esquerda, mas sim a ultima incidência encontrada.

? at(".","abcd.ef.") //retorna 5
? rat(".","abcd.ef.") //retorna 8

Difícil um pouco de entender lá no manual.

Saudações,
Itamar M. Lins Jr.

At() e RAt()

Enviado: 13 Out 2016 16:59
por Jairo Maia
Itamar M. Lins Jr. escreveu:Mas o RAt() não retorna da direita para esquerda, mas sim a ultima incidência encontrada.
Sim. Mas o manual diz isso mesmo. Retorna a última posição do caractere dentro de uma string se apena 2 parâmetros forem definidos:
xHarbour Reference Documentation > Function Reference
RAt()
Locates the position of a substring within a character string.
Syntax
RAt( <cSearch>, <cString>, [<nStart>], [<nEnd>] ) --> nPos
Arguments
<cSearch>
<cSearch> is the substring to search for.
<cString>
<cString> is the searched character string.
<nStart>
A numeric expression indicating the position of the first character in <cString> to begin the search with. It defaults to Len(<cString>).
<nEnd>
A numeric expression indicating the position of the last character in <cString> to include in the search. It defaults to 1. Return
The function returns a numeric value which is the position in <cString> where <cSubString> is found. The return value is zero when <cSubString> is not found.
Description
This function RAt() searches the string <cString> from right to left for the character string <cSearch>. The search begins at position <nStart> and is case-sensitive. If <cString> does not contain <cSearch>, the function returns 0.
Note: use function At() to search <cString> from left to right.

At() e RAt()

Enviado: 14 Out 2016 10:33
por Kapiaba
Seria isto:

Código: Selecionar todos

Function Main()
 
   local nA:=0.01, nB:=0.001, cA, cB, cTa, cTb

   cA := transform(nA,"@L")

   ? at(".",cA) //return 11

   cB := transform(nB,"@L")

   ? rat(".",cB) //return 11

   cTa := Right( cA, At( ".", cA ) - 1  )

   ? cTa

   cTb := Right( cB, Rat( ".", cB ) - 1 )

   ? cTb

Return Nil
Abs

At() e RAt()

Enviado: 14 Out 2016 12:10
por Toledo
Itamar M. Lins Jr. escreveu:Não deveria ser 4 em rat() ?
Amigos, a única diferença entre AT() e RAT() é o lado que vai iniciar a busca, AT() da esquerda para a direita e RAT() da direita para a esquerda, mas a posição do caracter buscado continua sendo contado da esquerda para a direita.

Por exemplo:

Código: Selecionar todos

AB="1234567890.123"
? AT(".",AB) //posição 11
? RAT(".",AB) //posição 11

CD="1234567890.123.12"
? AT(".",CD) //posição 11
? RAT(".",CD) //posição 15
Abraços,