GO语言"path/filepath"包中"Join"函数的用法及代码示例。
用法:
func Join(elem ...string) string
Join 将任意数量的路径元素连接到单个路径中,并使用特定于操作系统的分隔符将它们分隔开。空元素被忽略。结果是已清理。但是,如果参数列表为空或其所有元素都为空,则 Join 返回一个空字符串。在 Windows 上,仅当第一个非空元素是 UNC 路径时,结果才会是 UNC 路径。
例子:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println("On Unix:")
fmt.Println(filepath.Join("a", "b", "c"))
fmt.Println(filepath.Join("a", "b/c"))
fmt.Println(filepath.Join("a/b", "c"))
fmt.Println(filepath.Join("a/b", "/c"))
fmt.Println(filepath.Join("a/b", "../../../xyz"))
}
输出:
On Unix: a/b/c a/b/c a/b/c a/b/c ../xyz
相关用法
- GO Join用法及代码示例
- GO PutUvarint用法及代码示例
- GO Scanner.Scan用法及代码示例
- GO LeadingZeros32用法及代码示例
- GO NewFromFiles用法及代码示例
- GO Regexp.FindString用法及代码示例
- GO Time.Sub用法及代码示例
- GO Regexp.FindAllIndex用法及代码示例
- GO Encode用法及代码示例
- GO ResponseRecorder用法及代码示例
- GO Value用法及代码示例
- GO StreamWriter用法及代码示例
- GO Fscanln用法及代码示例
- GO Values.Get用法及代码示例
- GO NumError用法及代码示例
- GO TrailingZeros8用法及代码示例
- GO Logger.Output用法及代码示例
- GO Float.SetString用法及代码示例
- GO NewReader用法及代码示例
- GO Tx.ExecContext用法及代码示例
注:本文由纯净天空筛选整理自golang.google.cn大神的英文原创作品 Join。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。