Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONPublished

At

At( <cSearch>, <cString> ) --> nPosition

Returns the first position of one text inside another string.

StringsSearchTextLocalizaçãoFunções essenciais
01 · OVERVIEW

Overview

Returns the first position of one text inside another string. This page was created from the historical training material and structured for quick reference, with practical notes and cautious use in current Protheus environments.

02 · SYNTAX

Syntax

At( <cSearch>, <cString> ) --> nPosition

Parameters

cSearch
CharacterRequired

Parameter used by the function. Check the Portuguese source page for the detailed original wording while this entry remains under review.

cString
CharacterRequired

Parameter used by the function. Check the Portuguese source page for the detailed original wording while this entry remains under review.

03 · PRACTICAL EXAMPLE

Finding an e-mail separator

User Function ExAtEmail()
    Local cEmail := "user@company.com"
    Local nPosition := At("@", cEmail)

    If nPosition > 0
        MsgInfo("User: " + SubStr(cEmail, 1, nPosition - 1))
    Else
        MsgStop("E-mail without @ separator.")
    EndIf
Return
Expected result

The @ position allows extracting the user part before the domain.

BEST PRACTICES
  • Use At() quando precisar da primeira ocorrência de um separador ou marcador.
  • Combine com SubStr() para extrair a parte anterior ou posterior ao texto encontrado.
  • Para localizar a última ocorrência, use Rat().
  • Teste o retorno maior que zero antes de usar a posição em cálculos de SubStr().
COMMON PITFALLS
  • This entry is under review because it was structured from historical training material.
  • Confirm behavior in the Protheus/AppServer release used in your environment.

Related content

REFERENCES
  1. TOTVS. At. TOTVSTEC / TDN. Official reference for locating the first occurrence in a string.
  2. Programação em ADVPL Completo. Training material recorded in the official documentation, section 4.5.4, p. 45-50. Summarized, reviewed and examples adapted.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha