String Manipulation to Mask Format

Good night guys
I’m new to knime and here I am doing a string manipulation
I would like to know how do I format CNPJ and CPF to 14 digits

Hello @Rafaeloneil,

what are CNPJ and CPF? And what is logic behind formatting? It would be best if you could share some input data (dummy data works fine), desired output and logic between it if not clear from data.


1 Like

I think
CNPJ is the passport number in brazil
(Cadastro Nacional da Pessoa Jurídica)

The CNPJ consists of a 14-digit number formatted as 00.000.000/0001-00 — The first eight digits identify the company, the four digits after the slash identify the branch or subsidiary (“0001” defaults to the headquarters), and the last two are check digits.

CPF could be the Brazilian individual taxpayer registry identification :thinking:

This number is attributed by the Brazilian Federal Revenue to Brazilians and resident aliens who, directly or indirectly, pay taxes in Brazil.[1] It is an 11-digit number in the format 000.000.000-00

But I also think an example of the desired input->masking would be helpful

@Rafaeloneil would it be enough for you if all numbers are hidden as “X”?
and masked

1 Like

Use the padleft function in the string manipulation node ( Just my guess)


The following model would be sufficient:
Sem título

1 Like

It would be something like that
Sem título

1 Like

Hi @Rafaeloneil,

i think you can then just use

->Replace comma , with nothing

Then use the string manipulation node:

and use lpad/padleft function to add the leading 0.
(you could also use only the String manipulation node and just to the replace there as well)