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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。