How to check if a string contains identical digits in Swift

1 Answer

0 votes
import Foundation

func isStringContainIdenticalDigits(_ s: String) -> Bool {
    return Set(s).count == 1
}

let s1 = "88888888"
print(isStringContainIdenticalDigits(s1)) 

let s2 = "999999991"
print(isStringContainIdenticalDigits(s2)) 



/*
run:

true
false

*/

 



answered Dec 31, 2024 by avibootz

Related questions

1 answer 195 views
1 answer 203 views
1 answer 196 views
1 answer 219 views
1 answer 211 views
1 answer 192 views
1 answer 251 views
...