Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

String manipulation in AdvPL

Combines text search, slicing and replacement.

String manipulation in AdvPLAdvPL
01 · OVERVIEW

Overview

AllTrim removes outer spaces. At finds the first occurrence and RAt the last; zero means absent. SubStr uses a one-based start and length, while Stuff removes a count and inserts text into a new string. Lower/Upper change case; Asc/Chr map character codes. Len measures representation length rather than a universal Unicode character count. This example uses fixed ASCII inputs. (Sources: refs. 1–10.)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed409()
    Local cText := "  AB-CD-AB  "
    // Normalize before calculating positions.
    cText := AllTrim(cText)
    ConOut(cValToChar(Len(cText)))
    ConOut(cValToChar(At("-",cText)))
    ConOut(cValToChar(RAt("-",cText)))
    ConOut(SubStr(cText,4,2))
    ConOut(Stuff(cText,4,2,"XY"))
    ConOut(Lower(cText))
    ConOut(Upper(Lower(cText)))
    ConOut(cValToChar(Asc("A")))
    ConOut(Chr(65))
Return Nil
Expected result

8; 3; 6; CD; AB-XY-AB; ab-cd-ab; AB-CD-AB; 65; A. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check absence before using a position; define input encoding.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. AllTrim. TDN. Accessed on 2026-10-26.
  2. TOTVS. Asc. TDN. Accessed on 2026-10-26.
  3. TOTVS. At. TDN. Accessed on 2026-10-26.
  4. TOTVS. Chr. TDN. Accessed on 2026-10-26.
  5. TOTVS. Len. TDN. Accessed on 2026-10-26.
  6. TOTVS. Lower. TDN. Accessed on 2026-10-26.
  7. TOTVS. RAt. TDN. Accessed on 2026-10-26.
  8. TOTVS. Stuff. TDN. Accessed on 2026-10-26.
  9. TOTVS. SubStr. TDN. Accessed on 2026-10-26.
  10. TOTVS. Upper. TDN. Accessed on 2026-10-26.
Status
Under review
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