Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
strings.TrimSpace removes character of new line
5,213 views
Skip to first unread message
Archos
unread,
Oct 4, 2010, 4:59:31 AM
10/4/10
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
It could be that new line character is defined in Unicode as a white
space.
* * *
package main
import (
"fmt"
"strings"
)
func main() {
l := "\tstairway to heaven \n"
fmt.Println("^" + l + "$")
fmt.Println("^" + strings.TrimSpace(l) + "$")
}
* * *
Andrew Gerrand
unread,
Oct 4, 2010, 5:02:16 AM
10/4/10
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Archos, golang-nuts
On 4 October 2010 19:59, Archos <
raul...@sent.com
> wrote:
> It could be that new line character is defined in Unicode as a white
> space.
Yes, a newline is considered white space.
Andrew
peterGo
unread,
Oct 4, 2010, 8:21:42 AM
10/4/10
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Archos,
Consider the Go package source code as part of the documentation.
strings func TrimSpace
http://golang.org/pkg/strings/#TrimSpace
http://golang.org/src/pkg/strings/strings.go#L497
return TrimFunc(s, unicode.IsSpace)
unicode func IsSpace
http://golang.org/pkg/unicode/#IsSpace
http://golang.org/src/pkg/unicode/letter.go#L130
switch rune {
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
return true
}
return false
It's that easy.
Peter
Reply all
Reply to author
Forward
0 new messages