Skip to content

Instantly share code, notes, and snippets.

@tpdns90321
Created April 12, 2016 11:34
Show Gist options
  • Save tpdns90321/3a847748fa2ae10e706806067e5377f1 to your computer and use it in GitHub Desktop.
Save tpdns90321/3a847748fa2ae10e706806067e5377f1 to your computer and use it in GitHub Desktop.
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
}
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