要去掉字符串中的所有"/",可以使用replacingOccurrences(of:with:)方法。该方法将字符串中的指定子字符串替换为另一个字符串。

以下是一个示例代码,演示如何去掉字符串中的所有"/":

let str = "Hello/World/!"

let result = str.replacingOccurrences(of: "/", with: "")
print(result)

输出结果为:

HelloWorld!

在上面的示例中,我们定义了一个字符串str,其中包含了多个"/"字符。然后,我们使用replacingOccurrences(of:with:)方法将所有的"/"替换为空字符串""。最后,打印输出结果。

Swift去掉字符串所有

原文地址: http://www.cveoy.top/t/topic/jfzh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录