gpt4 book ai didi

swift - 从 swift 字符串中删除时间戳

转载 作者:行者123 更新时间:2023-11-30 12:14:01 26 4
gpt4 key购买 nike

我正在创建一个应用程序,从给定的巨大多行字符串中删除新行和时间戳。我设法使用 string.replacingOccurences(of:_, by:_) 删除了新行,但找不到摆脱时间戳的方法。这是示例字符串的片段:

6:08phones and laptops connected to the free
6:10public Wi-Fi network due to this she
6:12could hack email accounts online bank
6:14accounts and other passwords however she
6:17had no deep knowledge of computers or
6:19hacking so how did she do this
6:21well she simply watched an 11 minute
6:23YouTube video on how to do it she was
6:25later hired by a VPN website which tests
6:27security that's one way to land a job
6:30and that just about wraps up this video
6:32check out the poll in the top right
6:34corner
6:35you guys can vote for the most
6:36surprising hacker but as always thanks
6:38for watching check out some more videos
6:40on screen right now leave a like if you
6:42enjoyed and if you haven't already what
6:44are you waiting for subscribe

最佳答案

尝试以下代码仅从字符串中删除时间戳。

(时间戳只能采用此格式。如果格式更改,可能会出现问题。)

let string = "6:42enjoyed and if you haven't already what"
let result = string.trimmingCharacters(in: CharacterSet(charactersIn: "01234567890:"))
print(result)

控制台打印:-
很喜欢,如果你还没有的话

关于swift - 从 swift 字符串中删除时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45650034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com