How to mask a string in swift 4.2
up vote
0
down vote
favorite
I wanna make a mask in a string.
let unmasked = "12345678900"
//string masked = "123.456.789-00"
This is the braziliam CPF format, i found nothing in Stack Overflow BR
swift4.2
add a comment |
up vote
0
down vote
favorite
I wanna make a mask in a string.
let unmasked = "12345678900"
//string masked = "123.456.789-00"
This is the braziliam CPF format, i found nothing in Stack Overflow BR
swift4.2
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wanna make a mask in a string.
let unmasked = "12345678900"
//string masked = "123.456.789-00"
This is the braziliam CPF format, i found nothing in Stack Overflow BR
swift4.2
I wanna make a mask in a string.
let unmasked = "12345678900"
//string masked = "123.456.789-00"
This is the braziliam CPF format, i found nothing in Stack Overflow BR
let unmasked = "12345678900"
//string masked = "123.456.789-00"
let unmasked = "12345678900"
//string masked = "123.456.789-00"
swift4.2
swift4.2
asked Nov 21 at 14:05
Maicon Santos
93
93
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I found a solution using a character array and array.insert to insert mask in defined index
Portuguese:
Eu encontrei uma solução usando um array de caracteres e a função array.insert que permite inserir qualquer string em um determinado index da matriz.
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
add a comment |
up vote
0
down vote
You could use this gist in your project :-
StringFormattor
Usage :
var maskedResult = unmasked.format("NNN.NNN.NNN-NN", oldString: "unmasked")
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I found a solution using a character array and array.insert to insert mask in defined index
Portuguese:
Eu encontrei uma solução usando um array de caracteres e a função array.insert que permite inserir qualquer string em um determinado index da matriz.
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
add a comment |
up vote
0
down vote
I found a solution using a character array and array.insert to insert mask in defined index
Portuguese:
Eu encontrei uma solução usando um array de caracteres e a função array.insert que permite inserir qualquer string em um determinado index da matriz.
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
add a comment |
up vote
0
down vote
up vote
0
down vote
I found a solution using a character array and array.insert to insert mask in defined index
Portuguese:
Eu encontrei uma solução usando um array de caracteres e a função array.insert que permite inserir qualquer string em um determinado index da matriz.
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
I found a solution using a character array and array.insert to insert mask in defined index
Portuguese:
Eu encontrei uma solução usando um array de caracteres e a função array.insert que permite inserir qualquer string em um determinado index da matriz.
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
let cpf = "12345678900"
var characters = Array(cpf) //making a character array (criando um array de caracteres)
characters.insert(".", at: 3) //inserting "." in index 3 (inserindo "." no index 3)
//character = ["1","2","3",".","4","5","6","7","8","9","0","0"]
characters.insert(".", at: 7) // inserting "." in index 7 (inserindo "." no index 7)
//character = ["1","2","3",".","4","5","6",".","7","8","9","0","0"]
characters.insert("-", at: 11)// inserting "." in index 11 (inserindo "." no index 11)
//character = ["1","2","3",".","4","5","6",".","7","8","9","-","0","0"]
let masked = String(characters) //convert character to string
pint("cpf masked: ",masked)
//the masked will show: 123.456.789-00 (a mascara irá mostrar: 123.456.789-00)
answered Nov 21 at 14:53
Maicon Santos
93
93
add a comment |
add a comment |
up vote
0
down vote
You could use this gist in your project :-
StringFormattor
Usage :
var maskedResult = unmasked.format("NNN.NNN.NNN-NN", oldString: "unmasked")
add a comment |
up vote
0
down vote
You could use this gist in your project :-
StringFormattor
Usage :
var maskedResult = unmasked.format("NNN.NNN.NNN-NN", oldString: "unmasked")
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use this gist in your project :-
StringFormattor
Usage :
var maskedResult = unmasked.format("NNN.NNN.NNN-NN", oldString: "unmasked")
You could use this gist in your project :-
StringFormattor
Usage :
var maskedResult = unmasked.format("NNN.NNN.NNN-NN", oldString: "unmasked")
answered Nov 26 at 11:22
Ajay Singh Mehra
363112
363112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413851%2fhow-to-mask-a-string-in-swift-4-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown