Re: [go-nuts] String Split Question

2016-07-21 Thread roger peppe
I'd do something like this: https://play.golang.org/p/w4b4z0tVQ8 but it really depends on the details of the encoding and how robust you want to be with malformed records. For example, should "[foo[bar]baz]" be treated as ["foo[bar]baz"], ["foo[bar"], ["foo[bar", "baz"] or as an error ? On 21 Jul

Re: [go-nuts] String Split Question

2016-07-20 Thread rogerjd
This handles empty fields [], by adding them to a list of fields or ignoring them (it's up to you). I would think a case such as , is an error. That could be handled by state machine, ie: Close delim found, with no Open delim, That would be easy enough to code. https://play.golang.org/p/TVsp

Re: [go-nuts] String Split Question

2016-07-07 Thread Ignazio Di Napoli
On Thursday, July 7, 2016 at 12:05:27 AM UTC+2, Justin Israel wrote: > > https://play.golang.org/p/fOFT2voh6l >> > > That's pretty sweet. > Pretty sweet indeed, but it's worth saying that if the string is [field 1][field 2][][field 4] the result is ["field 1", "field 2", "field4"], ignoring the

Re: [go-nuts] String Split Question

2016-07-06 Thread Justin Israel
On Thu, Jul 7, 2016 at 7:43 AM Edward Muller wrote: > https://play.golang.org/p/fOFT2voh6l > That's pretty sweet. > > On Jul 5, 2016, at 2:57 PM, Freeman Fridie wrote: > > I have a data file with records in the following format: > > [field 1][field 2][field 3][field 4]... > > I need to be abl

Re: [go-nuts] String Split Question

2016-07-06 Thread Edward Muller
https://play.golang.org/p/fOFT2voh6l > On Jul 5, 2016, at 2:57 PM, Freeman Fridie wrote: > > I have a data file with records in the following format: > > [field 1][field 2][field 3][field 4]... > > I need to be able to split the record into fields using

Re: [go-nuts] String Split Question

2016-07-05 Thread Matt Harden
One way to do it would be to use strings.Split to split at every "]", and then drop the leading "[" from each field. Are the fields themselves guaranteed not to contain "]", or is there some escaping mechanism that allows them, in which case things get more complex? You could also just drop the le

[go-nuts] String Split Question

2016-07-05 Thread Freeman Fridie
I have a data file with records in the following format: [field 1][field 2][field 3][field 4]... I need to be able to split the record into fields using [ ] as the delimeter. I assume I need to use regex, but I'm unsure how to proceed. thanks, -- You received this message because you are s