GoLang
xxxxxxxxxx
package main
import (
"fmt"
"path/filepath"
"strings"
)
func main() {
p := filepath.Join("dir1", "dir2", "filename")
fmt.Println("p:", p)
fmt.Println(filepath.Join("dir1//", "filename"))
fmt.Println(filepath.Join("dir1/../dir1", "filename"))
fmt.Println("Dir(p):", filepath.Dir(p))
fmt.Println("Base(p):", filepath.Base(p))
fmt.Println(filepath.IsAbs("dir/file"))
fmt.Println(filepath.IsAbs("/dir/file"))
filename := "config.json"
ext := filepath.Ext(filename)
fmt.Println(ext)
fmt.Println(strings.TrimSuffix(filename, ext))
rel, err := filepath.Rel("a/b", "a/b/t/file")
if err != nil {
panic(err)
}
fmt.Println(rel)
rel, err = filepath.Rel("a/b", "a/c/t/file")
if err != nil {
panic(err)
}
fmt.Println(rel)
}
p: dir1/dir2/filename dir1/filename dir1/filename Dir(p): dir1/dir2 Base(p): filename false true .json config t/file ../c/t/file
Linux - How to Install anc-api-tools
Linux - How to Install curvedns
Linux - How to Install zenmap
Python - Check if a Number is Positive, Negative or 0
C - Count Number of Digits in an Integer
C++ - Check Whether a Number is Prime or Not
JavaScript - Check Whether a String Starts and Ends With Certain Characters
C - Find Largest Number Using Dynamic Memory Allocation
Kotlin - Reverse a Number
Kotlin - Round a Number to n Decimal Places
C++ - Check Leap Year
Linux - How to Install zfs-test
Linux - How to Install zstd
GoLang - Base64 Encoding
Java - Reverse a Number
Kotlin - Find Factorial of a Number
C++ - Find Quotient and Remainder
PHP - Array in Descending Order
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month