I’m working on a small script that compares two strings. I’ve tested the following with various strings and it returns the correct value yet in this case it says there are only eight differences when there are nine.
myName := "GGACGGATTCTG"
yourName := "AGGACGGATTCT"
var count int
l := len(myName)
for z := 0; z < (l - 1); z++ {
x := string((myName)[z])
y := string((yourName)[z])
if x != y {
count = count + 1
}
}
fmt.Println(count)
I ended up with this as I still don’t know how to use range properly
func main() {
var (
a = "GGACGGATTCTG"
b = "AGGACGGATTCT"
count int
)
if len(a) != len(b) {
os.Exit(1)
}
fmt.Println("The string is", len(a), "characters long")
for z := 0; z < (len(a)); z++ {
x := a[z]
y := b[z]
if x != y {
count = count + 1
}
}
if count == 0 {
fmt.Println("There were no differences")
} else if count == 1 {
fmt.Println("There is 1 character that is different")
} else {
fmt.Println("There are", count, "characters that are different")
}
}