Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Sep 2008 18:49:08 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        unga888@yahoo.com
Cc:        freebsd-questions@freebsd.org
Subject:   Re: How to split a C string by a string?
Message-ID:  <87od2mn56z.fsf@kobe.laptop>
In-Reply-To: <417898.61773.qm@web57005.mail.re3.yahoo.com> (Unga's message of "Wed, 17 Sep 2008 06:32:56 -0700 (PDT)")
References:  <417898.61773.qm@web57005.mail.re3.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 17 Sep 2008 06:32:56 -0700 (PDT), Unga <unga888@yahoo.com> wrote:
> --- On Wed, 9/17/08, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
>> From: Giorgos Keramidas <keramida@ceid.upatras.gr>
>> Subject: Re: How to split a C string by a string?
>> To: unga888@yahoo.com
>> Cc: freebsd-questions@freebsd.org
>> Date: Wednesday, September 17, 2008, 6:17 PM
>> On Wed, 17 Sep 2008 00:45:46 -0700 (PDT), Unga
>> <unga888@yahoo.com> wrote:
>> > Hi all
>> >
>> > I'm writing an C application on FreeBSD 7+. I need to split a
>> > string by another string (ie. the delimiter is "xxx") similar to
>> > strtok split a string by a single char. Is there a standard
>> > function or is there a FreeBSD functions for this?
>>
>> You can use strstr() to look for the "xxx" delimited and split that
>> that point: [snip sample code]
>
> Thank you very much for the reply. That is, there is no existing split
> function. So I got to write to my own :)

Yes, you have to roll our own.  The standard C library doesn't have
string splitting functions with a string as delimiter.  It includes
strtok(), strspn() and strcspn(), but these work with character sets as
delimiters, not strings...




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87od2mn56z.fsf>