How to masking textfield in Swift 4? [duplicate] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to masking the last number in Swift?How to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?Swift Beta performance: sorting arraysSplit a String into an array in Swift?Special dot masked input HTML-JavaScriptMask 9 digits SSN number in sql LogsHow to masking the last number in Swift?
How to convince students of the implication truth values?
Do I really need to have a message in a novel to appeal to readers?
Closed form of recurrent arithmetic series summation
What is the meaning of the simile “quick as silk”?
How do I make this wiring inside cabinet safer? (Pic)
Most bit efficient text communication method?
What does this Jacques Hadamard quote mean?
How would a mousetrap for use in space work?
What is the longest distance a player character can jump in one leap?
Is it a good idea to use CNN to classify 1D signal?
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
Using audio cues to encourage good posture
What causes the direction of lightning flashes?
Did MS DOS itself ever use blinking text?
Do square wave exist?
Significance of Cersei's obsession with elephants?
How come Sam didn't become Lord of Horn Hill?
8 Prisoners wearing hats
Is safe to use va_start macro with this as parameter?
When the Haste spell ends on a creature, do attackers have advantage against that creature?
Do I really need recursive chmod to restrict access to a folder?
Dating a Former Employee
Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?
Can a new player join a group only when a new campaign starts?
How to masking textfield in Swift 4? [duplicate]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to masking the last number in Swift?How to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?Swift Beta performance: sorting arraysSplit a String into an array in Swift?Special dot masked input HTML-JavaScriptMask 9 digits SSN number in sql LogsHow to masking the last number in Swift?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
How to masking the last number in Swift?
1 answer
I want masking email in textfield.text, but I only get the value in the middle. I want to get the value from the middle to @ gmail.com like example below.
ex:
- let var = 12345678@gmail.com
output = ****5678@gmail.com
- let var = 123456789@gmail.com
output = ****56789@gmail.com
let email = "123456789@gmail.com"
let components = email.components(separatedBy: "@")
let result = hideMidChars(components.first!) + "@" + components.last!
print(result)
output I get: ****5****@gmail.com
my expectations: ****56789@gmail.com
swift textfield masking
marked as duplicate by Johnykutty, vadian
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 10:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to masking the last number in Swift?
1 answer
I want masking email in textfield.text, but I only get the value in the middle. I want to get the value from the middle to @ gmail.com like example below.
ex:
- let var = 12345678@gmail.com
output = ****5678@gmail.com
- let var = 123456789@gmail.com
output = ****56789@gmail.com
let email = "123456789@gmail.com"
let components = email.components(separatedBy: "@")
let result = hideMidChars(components.first!) + "@" + components.last!
print(result)
output I get: ****5****@gmail.com
my expectations: ****56789@gmail.com
swift textfield masking
marked as duplicate by Johnykutty, vadian
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 10:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
its clear that issue with functionhideMidChars
. Is it your own function?
– Johnykutty
Mar 22 at 9:40
1
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05
add a comment |
This question already has an answer here:
How to masking the last number in Swift?
1 answer
I want masking email in textfield.text, but I only get the value in the middle. I want to get the value from the middle to @ gmail.com like example below.
ex:
- let var = 12345678@gmail.com
output = ****5678@gmail.com
- let var = 123456789@gmail.com
output = ****56789@gmail.com
let email = "123456789@gmail.com"
let components = email.components(separatedBy: "@")
let result = hideMidChars(components.first!) + "@" + components.last!
print(result)
output I get: ****5****@gmail.com
my expectations: ****56789@gmail.com
swift textfield masking
This question already has an answer here:
How to masking the last number in Swift?
1 answer
I want masking email in textfield.text, but I only get the value in the middle. I want to get the value from the middle to @ gmail.com like example below.
ex:
- let var = 12345678@gmail.com
output = ****5678@gmail.com
- let var = 123456789@gmail.com
output = ****56789@gmail.com
let email = "123456789@gmail.com"
let components = email.components(separatedBy: "@")
let result = hideMidChars(components.first!) + "@" + components.last!
print(result)
output I get: ****5****@gmail.com
my expectations: ****56789@gmail.com
This question already has an answer here:
How to masking the last number in Swift?
1 answer
swift textfield masking
swift textfield masking
edited Mar 22 at 12:10
Cœur
19.4k10116155
19.4k10116155
asked Mar 22 at 9:33
edo oktarifaedo oktarifa
206
206
marked as duplicate by Johnykutty, vadian
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 10:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Johnykutty, vadian
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 10:17
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
its clear that issue with functionhideMidChars
. Is it your own function?
– Johnykutty
Mar 22 at 9:40
1
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05
add a comment |
its clear that issue with functionhideMidChars
. Is it your own function?
– Johnykutty
Mar 22 at 9:40
1
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05
its clear that issue with function
hideMidChars
. Is it your own function?– Johnykutty
Mar 22 at 9:40
its clear that issue with function
hideMidChars
. Is it your own function?– Johnykutty
Mar 22 at 9:40
1
1
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05
add a comment |
2 Answers
2
active
oldest
votes
func hide(email: String) -> String
let parts = email.split(separator: "@")
if parts.count < 2
return email
let name = parts[0]
let appendix = parts[1]
let lenght = name.count
if lenght == 1
return "*@(appendix)"
let semiLenght = lenght / 2
var suffixSemiLenght = semiLenght
if (lenght % 2 == 1)
suffixSemiLenght += 1
let prefix = String(repeating: "*", count: semiLenght)
let lastPart = String(name.suffix(suffixSemiLenght))
let result = "(prefix)(lastPart)@(appendix)"
return result
let email = "123456789@gmail.com"
let result = hide(email: email)
print(result)
add a comment |
try extending the string protocol and declare a variable which returns an .init(repeating: ,count):
extension StringProtocol
var masked: String
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
usage as follows:
let email = "123456789@gmail.com"
print(email.masked) //"••••••••••gmail.com"
if you want a part of the email showing just manipulate the suffix(count - 3) as follows:
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
func hide(email: String) -> String
let parts = email.split(separator: "@")
if parts.count < 2
return email
let name = parts[0]
let appendix = parts[1]
let lenght = name.count
if lenght == 1
return "*@(appendix)"
let semiLenght = lenght / 2
var suffixSemiLenght = semiLenght
if (lenght % 2 == 1)
suffixSemiLenght += 1
let prefix = String(repeating: "*", count: semiLenght)
let lastPart = String(name.suffix(suffixSemiLenght))
let result = "(prefix)(lastPart)@(appendix)"
return result
let email = "123456789@gmail.com"
let result = hide(email: email)
print(result)
add a comment |
func hide(email: String) -> String
let parts = email.split(separator: "@")
if parts.count < 2
return email
let name = parts[0]
let appendix = parts[1]
let lenght = name.count
if lenght == 1
return "*@(appendix)"
let semiLenght = lenght / 2
var suffixSemiLenght = semiLenght
if (lenght % 2 == 1)
suffixSemiLenght += 1
let prefix = String(repeating: "*", count: semiLenght)
let lastPart = String(name.suffix(suffixSemiLenght))
let result = "(prefix)(lastPart)@(appendix)"
return result
let email = "123456789@gmail.com"
let result = hide(email: email)
print(result)
add a comment |
func hide(email: String) -> String
let parts = email.split(separator: "@")
if parts.count < 2
return email
let name = parts[0]
let appendix = parts[1]
let lenght = name.count
if lenght == 1
return "*@(appendix)"
let semiLenght = lenght / 2
var suffixSemiLenght = semiLenght
if (lenght % 2 == 1)
suffixSemiLenght += 1
let prefix = String(repeating: "*", count: semiLenght)
let lastPart = String(name.suffix(suffixSemiLenght))
let result = "(prefix)(lastPart)@(appendix)"
return result
let email = "123456789@gmail.com"
let result = hide(email: email)
print(result)
func hide(email: String) -> String
let parts = email.split(separator: "@")
if parts.count < 2
return email
let name = parts[0]
let appendix = parts[1]
let lenght = name.count
if lenght == 1
return "*@(appendix)"
let semiLenght = lenght / 2
var suffixSemiLenght = semiLenght
if (lenght % 2 == 1)
suffixSemiLenght += 1
let prefix = String(repeating: "*", count: semiLenght)
let lastPart = String(name.suffix(suffixSemiLenght))
let result = "(prefix)(lastPart)@(appendix)"
return result
let email = "123456789@gmail.com"
let result = hide(email: email)
print(result)
answered Mar 22 at 10:39
VyacheslavVyacheslav
15.2k964127
15.2k964127
add a comment |
add a comment |
try extending the string protocol and declare a variable which returns an .init(repeating: ,count):
extension StringProtocol
var masked: String
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
usage as follows:
let email = "123456789@gmail.com"
print(email.masked) //"••••••••••gmail.com"
if you want a part of the email showing just manipulate the suffix(count - 3) as follows:
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
add a comment |
try extending the string protocol and declare a variable which returns an .init(repeating: ,count):
extension StringProtocol
var masked: String
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
usage as follows:
let email = "123456789@gmail.com"
print(email.masked) //"••••••••••gmail.com"
if you want a part of the email showing just manipulate the suffix(count - 3) as follows:
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
add a comment |
try extending the string protocol and declare a variable which returns an .init(repeating: ,count):
extension StringProtocol
var masked: String
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
usage as follows:
let email = "123456789@gmail.com"
print(email.masked) //"••••••••••gmail.com"
if you want a part of the email showing just manipulate the suffix(count - 3) as follows:
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
try extending the string protocol and declare a variable which returns an .init(repeating: ,count):
extension StringProtocol
var masked: String
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
usage as follows:
let email = "123456789@gmail.com"
print(email.masked) //"••••••••••gmail.com"
if you want a part of the email showing just manipulate the suffix(count - 3) as follows:
return String(repeating: "•", count: Swift.max(0, count - count/2)) + suffix(count/2)
answered Mar 22 at 9:50
Sanad BarjawiSanad Barjawi
11512
11512
add a comment |
add a comment |
its clear that issue with function
hideMidChars
. Is it your own function?– Johnykutty
Mar 22 at 9:40
1
Why doesn't this work for you?
– Joakim Danielson
Mar 22 at 9:40
but in this case i only masking from the beginning of the text to @gmail and devide by 2. example i have int with 8 number: 12345678@gmail.com masking only ****45678@gmail.com how about i have 10 number: 1234567890@gmail.com masking only *****67890@gmail.com i get data from Api, in that link we can add position masking from. how about from json, data is random. so i can't use that
– edo oktarifa
Mar 22 at 9:52
you may use same answer from your own question as @JoakimDanielson indicated. Change hardcoded 5 to half of the length of your string.
– Johnykutty
Mar 22 at 10:05