Go语言(又称Golang)是Google开发的一种静态强类型、编译型、并发型,并具有垃圾回收功能的编程语言。那么Go语言是如何实现出去文件后缀呢?
package main
import (
“fmt”
“path”
“strings”
)
func main() {
fullFilename := “/Users/itfanr/Documents/test.txt”
fmt.Println(“fullFilename =”, fullFilename)
var filenameWithSuffix string
filenameWithSuffix = path.Base(fullFilename)
fmt.Println(“filenameWithSuffix =”, filenameWithSuffix)
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix)
fmt.Println(“fileSuffix =”, fileSuffix)
var filenameOnly string
filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
fmt.Println("filenameOnly =", filenameOnly)
1var filenameOnly string
2filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
3fmt.Println("filenameOnly =", filenameOnly)
}
更多Go语言内容,请关注:http://www.fastgolang.com/
本文转载自:http://www.crifan.com/go_language_string_split_and_replace/
有疑问加站长微信联系(非本文作者)