Golang Illegal rune literal error when splitting string

6k views Asked by At

I am trying to split string based on split function in golang. But getting illegal rune literal error for r == '/--/' && r == '/-iN-/' && r == '/--/'

func Split(r rune) bool {
    return r == '/--/' && r == '/-iN-/' && r == '/--/'
}
1

There are 1 answers

1
LeGEC On BEST ANSWER

In Go, you can use single quotes for literal values that consist of a single character.

If you want to write a string literal, you should use double quotes or backticks :

'/'      // <- a single character
"/--/"   // <- a string
`/--/`   // <- also a string

You would also have to change your Split function because a rune cannot be compared to a string.