Created
April 12, 2016 11:34
-
-
Save tpdns90321/3a847748fa2ae10e706806067e5377f1 to your computer and use it in GitHub Desktop.
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 SplitLine | |
func SplitLine(raw string) (lines []string){ | |
lines = make([]string,1) | |
temp := "" | |
for _,ch := range raw{ | |
if ch == '\r'{ | |
continue | |
}else if ch == '\n'{ | |
lines = append(lines,temp) | |
temp = "" | |
continue | |
} | |
temp = temp + string(ch); | |
} | |
if temp != ""{ | |
lines = append(lines,temp); | |
} | |
return | |
} |
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 SplitLine | |
import "fmt" | |
func ExampleSplitLine(){ | |
raw := "Hello, WOrld,\r\nWe are the world\nhello" | |
for _,x := range SplitLine(raw){ | |
fmt.Println(x) | |
} | |
//Output: | |
//Hello, WOrld, | |
//We are the world | |
//hello | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment