在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
// // YYExtension.swift // // Created by yao_yu on 14-7-18. // Copyright (c) 2014年 yao_yu. All rights reserved. // import Foundation extension String{ func strip() -> String{ return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) } func split(separator: String) -> [String]{ return componentsSeparatedByString(separator) } var doubleValue:Double!{ return (self as NSString).doubleValue } var length:Int{ return countElements(self) } func isValidRange(range: Range<Int>) -> Bool{ return range.startIndex >= 0 && range.endIndex <= length } subscript (range: Range<Int>) -> String { assert(isValidRange(range), "范围超出字符串长度") var startIndex:String.Index = advance(self.startIndex, range.startIndex) var endIndex:String.Index = advance(startIndex, range.endIndex - range.startIndex) return self.substringWithRange(Range(start: startIndex, end: endIndex)) } subscript (index: Int) -> String{ return self[index...index] } func at (indexes: Int...) -> [String] { return indexes.map { self[$0] } } func at (indexes: [Int]) -> [String] { return indexes.map { self[$0] } } } extension Array { func take(n: Int) -> SliceType{ return self[0 ..< n] } func tail (n: Int) -> SliceType { return self[(count - n) ..< count] } func skip (n: Int) -> SliceType { return self[n ..< count] } } |
请发表评论