我有一个tableview,显示从一个tableview到另一个tableview的以下导航:
使用以下代码完成:
if var path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil)
if var content = (data){
//Breaks the entire String into individual strings at each newLine
var line: [String] = content.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())
//First Table - Displays Chapters
var lineArray = [line[0],
line[6],
line[12]]
我怎样才能读到它呢?
主题:食物,颜色,动物,汽车//each as a separate string.
如果我使用它,它将显示整行作为文本从"主题:...."所以基本上我要问的是,有没有办法阅读过去的主题,只是在食物上开始第一个字符串[0]?
答案 0 :(得分:0)
我不知道我是否理解你的问题,但我认为你想从字符串topics:
中跳过Topics: Food, Water, Melon, Car
....所以在将字符串分开之后你想要食指在索引0 ......
var str = "Topics: Food, color, animals, cars"
// Get location of first Space or any character you want
let loc = find(str, " ")
//Get the string from first space to end of string
let skipstr = Range(start: loc!,
end: str.endIndex)
let finalStr = str.substringWithRange(skipstr)
println(finalStr)
//Output:--> Food, color, animals, cars
然后将字符串与逗号
分开 let indexes = finalStr.componentsSeparatedByString(",")
println(indexes[0])
//And you got Food at index 0