我想在SWIFT中检查我的文件是否只存在文件名的前缀。
E.g
我的文件名与Companies_12344
相同所以在_值是动态的但是"公司_"是静态的。
我该怎么做?
我已经在
下面完成了分割文件名代码如何通过NSFileManager检查是否存在文件名"公司_"
int FEATURES = 10000;
OnlineLogisticRegression learningAlgorithm = new OnlineLogisticRegression(20, FEATURES, new L1())
.alpha(1).stepOffset(1000).decayExponent(0.9).lambda(3.0e-5).learningRate(20);
答案 0 :(得分:1)
我认为您需要此代码:
let str = "Companies_12344"
if str.hasPrefix("Companies") {
println("Yes, this one has 'Companies' as a prefix")
let compos = str.componentsSeparatedByString("_")
if let file = compos.first {
println("There was a code after the prefix: \(file)")
var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
var yourPath = paths.stringByAppendingPathComponent("\(file)_")
var checkValidation = NSFileManager.defaultManager()
if (checkValidation.fileExistsAtPath(yourPath))
{
println("FILE AVAILABLE");
}
else
{
println("FILE NOT AVAILABLE");
}
}
}