Ралица обнови решението на 25.10.2015 17:22 (преди над 2 години)
+package main
+
+import (
+ "bytes"
+ "strings"
+)
+
+func ExtractColumn(logContents string, column uint8) string {
+ var lines = strings.Split(logContents, "\n")
+
+ if len(lines) == 0 {
+ return ""
+ }
+
+ var resultBuffer bytes.Buffer
+
+ for lineCount := 0; lineCount < len(lines); lineCount++ {
+ var line = lines[lineCount]
+ line = strings.Trim(line, " \n")
+
+ if line != "" {
+ var pieces []string = strings.SplitN(line, " ", 4)
+
+ switch {
+ case pieces != nil && column == 0:
+ resultBuffer.WriteString(pieces[0])
+ resultBuffer.WriteString(" ")
+ resultBuffer.WriteString(pieces[1])
+ case pieces != nil && column == 1:
+ resultBuffer.WriteString(pieces[2])
+ case pieces != nil && column == 2:
+ resultBuffer.WriteString(pieces[3])
+ }
+
+ resultBuffer.WriteString("\n")
+ }
+ }
+
+ return resultBuffer.String()
+}