: is a rune that cannot be changed using string.Replace()?

856 views
Skip to first unread message

Curtis Paul

unread,
Feb 1, 2016, 4:20:59 PM2/1/16
to golang-nuts
Doing this...  
strings.Replace(mac_address, ':', '', -1)

causes this error...
cannot use ':' (type rune) as type string in argument to strings.Replace

What is another way to remove : from a string?


Brad Fitzpatrick

unread,
Feb 1, 2016, 4:31:56 PM2/1/16
to Curtis Paul, golang-nuts
Use double quotes, not single quotes.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Curtis Paul

unread,
Feb 3, 2016, 4:21:37 PM2/3/16
to golang-nuts, curti...@gmail.com
I tried it with double quotes and it does not remove the : from the string.

Brad Fitzpatrick

unread,
Feb 3, 2016, 4:46:48 PM2/3/16
to Curtis Paul, golang-nuts
It returns a new string. It doesn't modify the argument it's given. (It couldn't.)

John McKown

unread,
Feb 3, 2016, 4:54:46 PM2/3/16
to Curtis Paul, golang-nuts
I successfully did the following (transcript) on Fedora Linux 22

[tsh009@it-johnmckown-linux Golang]$ cat example7.go 
package main

import (
    "fmt"
    "strings"
)

func main() {
    mac_address:="0123:4567:89ab:cdef"
    bubba:=strings.Replace(mac_address,":","",-1)
    fmt.Println(mac_address,bubba)
}
[tsh009@it-johnmckown-linux Golang]$ go run example7.go 
# command-line-arguments
ar: `u' modifier ignored since `D' is the default (see `U')
0123:4567:89ab:cdef 0123456789abcdef
[tsh009@it-johnmckown-linux Golang]$ go version
go version go1.4.2 gccgo (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2) linux/amd64
[tsh009@it-johnmckown-linux Golang]$ uname -a
Linux it-johnmckown-linux 4.2.8-200.fc22.x86_64 #1 SMP Tue Dec 15 16:50:23 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[tsh009@it-johnmckown-linux Golang]$ 
--
Werner Heisenberg is driving down the autobahn. A police officer pulls
him over. The officer says, "Excuse me, sir, do you know how fast you
were going?"
"No," replies Dr. Heisenberg, "but I know where I am."

Computer Science is the only discipline in which we view adding a new wing to a building as being maintenance -- Jim Horning

Schrodinger's backup: The condition of any backup is unknown until a restore is attempted.

He's about as useful as a wax frying pan.

Maranatha! <><
John McKown

Brad Fitzpatrick

unread,
Feb 3, 2016, 5:17:26 PM2/3/16
to John McKown, Curtis Paul, golang-nuts
Your Go installation is broken.

I don't know how.

Dave Cheney

unread,
Feb 3, 2016, 7:54:09 PM2/3/16
to golang-nuts, john.arch...@gmail.com, curti...@gmail.com
Correction: your _gccgo_ installation is broken, or possibly intermingled with other parts of other Go installations.

John McKown

unread,
Feb 4, 2016, 9:06:35 AM2/4/16
to Dave Cheney, golang-nuts, Brad Fitzpatrick
Dave & Brad,

Blessing upon you both. I just removed Go, both the gcc-go & golang package versions, from my Fedora system. I then reinstalled _only_ the golang* packages. Things are working much better now. I had been having some _minor_ problems, but I figured it was due to ignorance of Go on my part. Those problems have now gone away.
Reply all
Reply to author
Forward
0 new messages