使用swift查找文件名和扩展名方法代码:
let fileName = "fileName.txt.swift"
let dotIndex = "fileName.lastIndex(of:".")"
let name = fileName[ ..< dotIndex]
let indexAfterDot = fileName.index(after:doutIndex)
let extension = fileName[indexAfterDot ..<fileName.endIndex]
print("name:\(name)")
print("extension:\(extension)")
Last login: Tue Sep 14 14:39:01 on console
software37@software37 ~ % cd workspace0302203223
software37@software37 workspace0302203223 % ls
algorithm algs4.jar cpp opp swift
software37@software37 workspace0302203223 % cd algorithm
software37@software37 algorithm % ;s
zsh: command not found: s
software37@software37 algorithm % ls
ArrayStack.java Flips.class Link.java algs4-data test.swift
Counter.class Flips.java Linkedst.java algs4-data.zip
Counter.java Flips.swift StackTest{} algs4.jar
software37@software37 algorithm % vi F
software37@software37 algorithm % ls
ArrayStack.java Flips.class Link.java algs4-data test.swift
Counter.class Flips.java Linkedst.java algs4-data.zip
Counter.java Flips.swift StackTest{} algs4.jar
software37@software37 algorithm % vi Counter.
software37@software37 algorithm % vi Counter.java
software37@software37 algorithm % vi Flips.java
software37@software37 algorithm % vi test.java
software37@software37 algorithm % vi Linkedst.java
software37@software37 algorithm % vi StackTest{}
software37@software37 algorithm % vi Stacktest
software37@software37 algorithm % vi StackTest.java
software37@software37 algorithm % vi test.swift
software37@software37 algorithm % ArrayStack.java
zsh: command not found: ArrayStack.java
software37@software37 algorithm % ArrayStack.java
zsh: command not found: ArrayStack.java
software37@software37 algorithm % ls
ArrayStack 2.java Flips.java algs4-data
ArrayStack.java Flips.swift algs4-data.zip
Counter.class Link.java algs4.jar
Counter.java Linkedst.java test.swift
Flips.class StackTest.java
software37@software37 algorithm % ArrayStack.java
zsh: command not found: ArrayStack.java
software37@software37 algorithm % Link.java
zsh: command not found: Link.java
software37@software37 algorithm % vi ArrayStack.java
software37@software37 algorithm % vi Average.java
software37@software37 algorithm % vi Bag.java
software37@software37 algorithm % vi Average.java
software37@software37 algorithm % VI Average.java
bag.add(x);
}
double m = a.mean();
double sum = 0;
for(double x:bag){
sum +=(x-m)*(x-m);
}
int n=bag.size()-1;
int n bag.size()-1;
double stderr =Math.sqrt(sum)/n;
StdOut.println(a);
StdOut.println("stderr:"+String.fromat("%.5f",stderr));
}
}