golang with compile error: undefined: strings in strings.trim

You're importing strings under an alias:

import  ss "strings"

That means that everywhere in that file, instead of referring to strings you must refer to ss, for example:

words := ss.Split(s," ")

If you use the default import:

import "strings"

Then you can refer to it as strings as normal.

Note that the currently accepted answer is wrong about two things: you can absolutely use the alias as you have it, you just have to refer to the package with the aliased name. It will not cause any issues if you use the name you gave it. Second, you absolutely do need to import the strings package - with or without an alias, your choice - if you want to refer to it.

On a completely unrelated side note, you should strongly consider running go fmt on your code, as it does not follow Go coding standards; for example, standard Go code omits the vast majority of semicolons. The code will work regardless, but you'll have an easier time getting help from other Go developers if your code is formatted the way everyone else is used to seeing it.

Tags:

Go