zoukankan      html  css  js  c++  java
  • 第1年4月25日 swift

    1.swift - 从指定路径的文件中读取数据

    func readPathLossFile(_ path: String) -> [[Substring]]? {
            let fileManager = FileManager.default
            if let url = URL.init(string: path) {
                if fileManager.fileExists(atPath: url.path) {
                    let txtData = fileManager.contents(atPath: url.path)
                    var dataArray:[[Substring]] = []
                    if txtData == nil {
                        return nil
                    }
                    let readString = String(data: txtData!, encoding: String.Encoding.utf8)
                    print("readString: (String(describing: readString))")
                    if readString!.contains("
    ") {
                        let dataOfRowArray = readString?.split(separator: "
    ")
                        for (_,rowString) in dataOfRowArray!.enumerated() {
                            let rowArray = rowString.split(separator: ",")
                            if rowArray.count > 0 {
                                dataArray.append(rowArray)
                            }
                        }
                    } else {
                        let dataOfRowArray = readString?.split(separator: "
    ")
                        for (_,rowString) in dataOfRowArray!.enumerated() {
                            let rowArray = rowString.split(separator: ",")
                            if rowArray.count > 0 {
                                dataArray.append(rowArray)
                            }
                        }
                    }
                    return dataArray
                }else {
                    print("Path loss file is not exists")
                    return nil
                }
            }
            return []
        }

    https://blog.csdn.net/u011598999/article/details/80108598

  • 相关阅读:
    java基础_面试题笔记
    ACM-ICPC 2018 Xuzhou Online Contest题解
    覆盖点问题总结
    2018icpc沈阳网络赛题解(转发)
    树链剖分
    树状数组
    线段树板子
    sdoi2016生成魔咒
    洛谷3804
    大佬博文收集
  • 原文地址:https://www.cnblogs.com/javastart/p/14702044.html
Copyright © 2011-2022 走看看