Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何在Swift中使用子字符串_String_Swift_Nsstring_Substring_Indexof - Fatal编程技术网

String 如何在Swift中使用子字符串

String 如何在Swift中使用子字符串,string,swift,nsstring,substring,indexof,String,Swift,Nsstring,Substring,Indexof,我对Swift中的子字符串非常着迷。我需要获取另一个字符串中“字符串”的实际索引,以确定最终输出的范围 有什么想法吗? 谢谢 这应该可以 编辑:修复。?我编辑了答案,所以现在应该可以编译了。我不能测试,因为我不在自动取款机上。 let yourString = "loremipsumSTRINGdolor" as NSString let range: NSRange = yourString.rangeOfString("STRING") let lenght = range.length

我对Swift中的子字符串非常着迷。我需要获取另一个字符串中“字符串”的实际索引,以确定最终输出的范围

有什么想法吗? 谢谢

这应该可以


编辑:修复。

?我编辑了答案,所以现在应该可以编译了。我不能测试,因为我不在自动取款机上。
let yourString = "loremipsumSTRINGdolor" as NSString
let range: NSRange = yourString.rangeOfString("STRING")
let lenght =  range.length
let location = range.location