golang split string by multiple delimitters

4,092 views
Skip to first unread message

Sankar

unread,
Jul 17, 2012, 6:11:47 AM7/17/12
to golan...@googlegroups.com
Hi,

I have a string "hello <format> world" and I need to split it based on multiple characters "<> ". How do I get this ? The strings.Fields splits only by space. strings.Split too doesn't work. I saw that FieldsFunc whose documentation looks like it might solve this. But I am not able to understand it as there are no examples. Also, the helper text is a bit confusing to me and I am not able to understand it clearly.

Can someone help me with the code for understanding how to split by multiple delimitters ? It may be good, if you can also get this added to the FieldsFunc API as an example code.

Thanks.

Sankar

Sonia Keys

unread,
Jul 17, 2012, 12:26:31 PM7/17/12
to golan...@googlegroups.com
A solution using a function literal:  http://play.golang.org/p/cLHpRxZQiG

Hope that helps!

Andy Balholm

unread,
Jul 17, 2012, 12:28:18 PM7/17/12
to golan...@googlegroups.com
Is http://play.golang.org/p/bArgFXBuha what you're looking for?
Reply all
Reply to author
Forward
0 new messages