0

I'm a newbie in Golang, so I'm playing with some algorithms and i have a little problem. In java for insert an end string in char array I can do like this:

String str = "Mr John Smith    ";
char[] arr = str.toCharArray();
arr[12] = '\0';

But in Golang I'm trying like this:

str := []byte("Mr John Smith    ")
str[12] = '\0'

But this code didn't work

1

1 Answer 1

6

That's not a valid syntax for a rune literal with a 0 value. You can use the hex escape sequence

str[12] = '\x00'

If you really need an octal value, it requires 3 digits

str[12] = '\000'

Or just assign a literal 0

str[12] = 0

You can see the valid rune literal escape sequences in the specification: https://golang.org/ref/spec#Rune_literals

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.