Андрея обнови решението на 03.11.2015 01:38 (преди над 2 години)
+package main
+
+import "strings"
+
+func ExtractColumn(logContents string, column uint8) (result string) {
+ lines := strings.Split(logContents, "\n")
+ lineLength := len(lines)
+
+ var getContent func(s string) string
+ switch {
+ case column == 0:
+ getContent = func(s string) string { return s[:19] }
+ case column == 1:
+ getContent = func(s string) string {
+ subs := s[20:len(s)]
+ subs = subs[:strings.Index(subs, " ")]
+ return subs
+ }
+ case column == 2:
+ getContent = func(s string) string {
+ subs := s[20:len(s)]
+ subs = subs[strings.Index(subs, " ")+1 : len(subs)]
+ return subs
+ }
+ }
+
+ for i := 0; i < lineLength; i++ {
+ if lines[i] != "" {
+ result += getContent(lines[i]) + "\n"
+ }
+ }
+
+ return
+}