2
我想从“SRC”的字符串。“数据lazy-”变量海峡,和它的工作时,我硬编码...如何从字符串强制转换为int
var str = "<h1 style=\"font-family: Helvetica\">Hello Pizza</h1><p>Tap the buttons above to see <strong>some cool stuff</strong> with <code>UIWebView</code><p><img src=\"https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg\" data-lazy-src=\"xxxxxxx\">"
str.rangeOfString(" src")?.startIndex
str.rangeOfString("data-lazy-")?.endIndex
let myNSString = str as NSString
myNSString.substringWithRange(NSRange(location: 150, length: 245-150))
结果:src=\"https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg\" data-lazy-
在这里,我想不硬编码它...
var str = "<h1 style=\"font-family: Helvetica\">Hello Pizza</h1><p>Tap the buttons above to see <strong>some cool stuff</strong> with <code>UIWebView</code><p><img src=\"https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg\" data-lazy-src=\"xxxxxxx\">"
str.rangeOfString(" src")?.startIndex
str.rangeOfString("data-lazy-")?.endIndex
let myNSString = str as NSString
let start = str.startIndex.toInt()
let end = str.endIndex.toInt()
myNSString.substringWithRange(NSRange(location: start, length: end - start))
上面的代码显示错误消息'String.index'没有名为'toInt'的成员 我的问题是我怎么能解决这个问题? 对不起,我是一个相当新的swift编程语言。
非常感谢! – KSL 2015-03-03 04:23:31