Swift 中的切片功能?
Slice Functionality in Swift?
我在 Swift 中阅读了我的 .zshrc 文件,并想打印出其中的所有别名。
func readFile(path: String) -> Int {
errno = 0
if freopen(path, "r", stdin) == nil {
perror(path)
return 1
}
while let line = readLine() {
if(line.starts(with: "# alias")){
print(line);
}
// do something with lines
}
return 0
}
现在输出是这样的
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# alias python="/usr/local/bin/python3.7"
# alias python2="/usr/bin/python2"
我想切掉 # alias
我该怎么做?
我是 swift.
的新手
提前致谢
感谢 Leo Dabus
dropFirst(8)
有效!
- 或查看
RangeReplaceableCollection
我在 Swift 中阅读了我的 .zshrc 文件,并想打印出其中的所有别名。
func readFile(path: String) -> Int {
errno = 0
if freopen(path, "r", stdin) == nil {
perror(path)
return 1
}
while let line = readLine() {
if(line.starts(with: "# alias")){
print(line);
}
// do something with lines
}
return 0
}
现在输出是这样的
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# alias python="/usr/local/bin/python3.7"
# alias python2="/usr/bin/python2"
我想切掉 # alias
我该怎么做?
我是 swift.
提前致谢
感谢 Leo Dabus
dropFirst(8)
有效!- 或查看
RangeReplaceableCollection