Pad 0 on the left [SOLVED]

Hey guys, I’m trying to pad a “0” to a string but I can’t find any solution, the following code gives me “830” as result but I need it to be “0830”, if it’s for example “8”, I need to get 0008, I tried a Printf example I found on Google but I got a compilation error;

https://play.golang.org/p/yreVifdKed

Appreciate any help, tnx.

Hey @leogazio, in your current case, you just need to replace your returnaCRC function with this:

func retornaCRC(hexstr string) string {
	hexbytes, _ := hex.DecodeString(hexstr)
	return fmt.Sprintf("%04x", CRC16([]byte(hexbytes)))
}

The problem there was that you were trying to use Printf, but you meant to use Sprintf.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.