ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.