Home > OS >  Golang Illegal rune literal error when splitting string
Golang Illegal rune literal error when splitting string

Time:07-22

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 == '/--/'
}

CodePudding user response:

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.

  • Related