filepath.Ext() Function in Golang With Examples
Last Updated :
10 May, 2020
In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.Ext() function in Go language used to return the file name extension used by the specified path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot. Moreover, this function is defined under the path package. Here, you need to import the “path/filepath” package in order to use these functions.
Syntax:
func Ext(path string) string
Here, ‘path’ is the specified path.
Return Value: It returns the file name extension used by the specified path.
Example 1:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println(filepath.Ext( "gfg.org" ))
fmt.Println(filepath.Ext( "GeeksforGeeks." ))
fmt.Println(filepath.Ext( ".org" ))
}
|
Output:
.org
.
.org
Example 2:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println(filepath.Ext( "a.b" ))
fmt.Println(filepath.Ext( "gfg" ))
fmt.Println(filepath.Ext( "ide.gfg.org" ))
fmt.Println(filepath.Ext( ".ab.cd" ))
}
|
Output:
.b
.org
.cd
Share your thoughts in the comments
Please Login to comment...