Last active
February 7, 2017 10:16
-
-
Save alwqx/b8da904e6c77a84434e41be6a266f754 to your computer and use it in GitHub Desktop.
golang deal with text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"strings" | |
"fmt" | |
) | |
func main() { | |
lines := "194 Temperature_Celsius 0x0022 037 045 000 Old_age Always - 37 (0 6 0 0 0)" | |
useSplit(lines) | |
useFields(lines) | |
} | |
func useSplit(lines string) { | |
line := strings.Split(lines, " ") | |
fmt.Println(line) | |
fmt.Println(len(line)) | |
} | |
func useFields(lines string) { | |
line := strings.Fields(lines) | |
fmt.Println(line) | |
fmt.Println(len(line)) | |
} | |
/* | |
output | |
➜ gist go run main.go | |
[194 Temperature_Celsius 0x0022 037 045 000 Old_age Always - 37 (0 6 0 0 0)] | |
42 | |
[194 Temperature_Celsius 0x0022 037 045 000 Old_age Always - 37 (0 6 0 0 0)] | |
15 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment