-3

Thanks for all the help and support, I am getting from this forum as a beginner. Now I am stuck with some other problem. I am generating uuid using "uuid.New()" method from "https://github.com/google/uuid" lib. Is there any method to remove hyphens from UUID?

Thanks

Anvy
  • 5
  • 1
  • 4
  • Actually the library I am using does not provide randomUUID generation. – Anvy May 16 '21 at 01:40
  • 3
    @Anvy The package referenced in the question does support random UUID generation. See [uuid.NewRandom](https://pkg.go.dev/github.com/google/uuid#NewRandom). – Charlie Tumahai May 16 '21 at 02:31

1 Answers1

4

The github.com/google/uuid package represents a UUID as an array of 16 bytes. The array is the raw data of UUID, not the hex encoded representation with hyphens.

No action is required to remove hyphens because the hyphens are not part of the data in the UUID value.

If you want to remove the hyphens from the string representation returned by the String method, simply use strings.Replace() as follows:

uuid := uuid.New().String()
uuidWithoutHyphens := strings.Replace(uuid, "-", "", -1)
Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
thwd
  • 74
  • 2