【发布时间】:2017-03-01 17:14:10
【问题描述】:
我想从以"<ONLINE>" 或"<OFFLINE>" (应该成为我的子字符串)开头的字符串中获取子字符串。当我尝试创建 Range 对象时,我可以使用 startIndex 轻松访问第一个字符,但是如何获取子字符串的右括号的索引,该索引将是完整字符串的第 8 个或第 9 个字符?
更新:
一个简单的例子:
let onlineString:String = "<ONLINE> Message with online tag!"
let substring:String = // Get the "<ONLINE> " part from my string?
let onlineStringWithoutTag:String = onlineString.replaceOccurances(of: substring, with: "")
// What I should get as the result: "Message with online tag!"
所以基本上,问题是:我要为substring 做什么?
【问题讨论】:
-
你能展示一些你如何创建你的范围对象的代码吗?
-
@MichaelDautermann 刚刚用一个例子更新了我的帖子。