FwString

Classe wrapper de string em TLPP com metodos fluentes. Substitui o spaghetti de AllTrim(Upper(StrTran(...))) com chain de metodos.

Assinatura: FwString(cValor):metodo()

Retorna: object

FwString e wrapper de string com metodos encadeaveis. Substitui o padrao classico AdvPL de aninhar funcoes: AllTrim(Upper(StrTran(cVar, '.', ''))).

Sintaxe basica

local oStr as object
oStr := FwString('  Joao Silva  ')

cResult := oStr:trim():toUpper():toString()
// 'JOAO SILVA'

Metodos uteis

local oStr as object
oStr := FwString(cTexto)

// Transformacao (todas retornam o proprio objeto - chainable)
oStr:trim()              // remove espacos das pontas
oStr:toUpper()           // maiuscula
oStr:toLower()           // minuscula
oStr:replace('a', 'b')   // substitui
oStr:padLeft(10, '0')    // preenche esquerda
oStr:padRight(20, ' ')   // preenche direita
oStr:reverse()           // inverte

// Consulta
oStr:length()            // tamanho
oStr:contains('texto')   // .T. se contem
oStr:startsWith('Joao')  // .T. se comeca
oStr:endsWith('Silva')   // .T. se termina
oStr:indexOf('S')        // posicao

// Final
cStr := oStr:toString()

Limpar CPF de uma vez

// AdvPL classico
cCpfLimpo := AllTrim(StrTran(StrTran(StrTran(cCpf, '.', ''), '-', ''), '/', ''))

// TLPP com FwString
cCpfLimpo := FwString(cCpf):trim():replace('.', ''):replace('-', ''):replace('/', ''):toString()

Quando usar

Parâmetros

NomeTipoObrigatórioDescrição
cValorCharactersimString inicial

Exemplos

Chain de transformacoes

cLimpo := FwString(cIn):trim():toUpper():replace('-','').toString()

Veja também