Golang os.IsPathSeparator() Function with Examples

Golang | os.IsPathSeparator() Function: Here, we are going to learn about the IsPathSeparator() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 25, 2021

os.IsPathSeparator()

In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The IsPathSeparator() function is an inbuilt function of the os package, it is used to check whether the given character (c) is a directory separator character or not.

It accepts one parameter (c uint8) and returns true if c is a directory separator; false, otherwise.

Syntax:

func IsPathSeparator(c uint8) bool

Parameter(s):

  • c - character to be checked whether it is a directory separator or not.

Return Value:

The return type of the os.IsPathSeparator() function is a bool, it returns true if c is a directory separator; false, otherwise.

Example:

// Golang program to demonstrate the
// example of IsPathSeparator() function

package main

import (
	"fmt"
	"os"
)

func main() {
	var c uint8 = '/'
	if os.IsPathSeparator(c) == true {
		fmt.Printf("%c is a directory separator\n", c)
	} else {
		fmt.Printf("%c is not a directory separator\n", c)
	}

	c = ':'
	if os.IsPathSeparator(c) == true {
		fmt.Printf("%c is a directory separator\n", c)
	} else {
		fmt.Printf("%c is not a directory separator\n", c)
	}

	c = '\\'
	if os.IsPathSeparator(c) == true {
		fmt.Printf("%c is a directory separator\n", c)
	} else {
		fmt.Printf("%c is not a directory separator\n", c)
	}
}

Output:

/ is a directory separator
: is not a directory separator
\ is not a directory separator

Golang os Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.