Skip to content

Instantly share code, notes, and snippets.

@chespinoza
Created July 24, 2013 21:32
Show Gist options
  • Save chespinoza/6074763 to your computer and use it in GitHub Desktop.
Save chespinoza/6074763 to your computer and use it in GitHub Desktop.
i/o to several floats
package main
import (
"bufio"
"fmt"
"strconv"
"strings"
)
func main() {
str := []byte("W=00.4 103 +20.4\r\n")
reader := bufio.NewReader(strings.NewReader(string(str)))
line, _ := reader.ReadString('\n')
if line[:1] == "W" {
WS, err := strconv.ParseFloat(line[2:6], 64)
if err != nil {
} else {
fmt.Println(WS)
}
WD, err := strconv.ParseFloat(line[7:10], 64)
if err != nil {
} else {
fmt.Println(WD)
}
WT, err := strconv.ParseFloat(line[11:16], 64)
if err != nil {
} else {
fmt.Println(WT)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment