有时候,项目中需要将手机号部分替换为*,例如 13800001111 显示为 138****1111,swift是如何实现的呢?来看代码吧!
var mobile = "13800001111"
mobile.replaceSubrange(mobile.index(mobile.startIndex, offsetBy: 3)..<mobile.index(mobile.startIndex, offsetBy: 7), with: "****")
Label.text = mobile
以下效果图:

网友评论