strtok vs split
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > strtok vs split




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    strtok vs split  
John Galt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-23-04 11:34 PM

Is there a C-language equivalent for Java's String.split()?
strtok() kind of sucks: it doesn't quite the same thing, it overwrites
its arg and it keeps track of stuff secretly between call to call.
There has *got* to be a better way. UNIX/C gurus, any ideas?

-John





[ Post a follow-up to this message ]



    Re: strtok vs split  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-23-04 11:35 PM

johngalt__@hotmail.com (John Galt) writes:

> Is there a C-language equivalent for Java's String.split()?
> strtok() kind of sucks: it doesn't quite the same thing, it overwrites
> its arg and it keeps track of stuff secretly between call to call.
> There has *got* to be a better way. UNIX/C gurus, any ideas?

There's always strtok_r() and strsep().

--
Måns Rullgård
mru@kth.se





[ Post a follow-up to this message ]



    Re: strtok vs split  
Dragan Cvetkovic


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-23-04 11:35 PM

Måns Rullgård <mru@kth.se> writes:

> johngalt__@hotmail.com (John Galt) writes:
> 
>
> There's always strtok_r() and strsep().
>

Strsep?

% man strsep
No manual entry for strsep.

% uname -sr
SunOS 5.10

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!





[ Post a follow-up to this message ]



    Re: strtok vs split  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-24-04 12:34 AM

Dragan Cvetkovic <me@privacy.net> writes:

> Måns Rullgård <mru@kth.se> writes:
> 
>
> Strsep?
>
> % man strsep
> No manual entry for strsep.
>
> % uname -sr
> SunOS 5.10

Apparently strsep exists only on BSD (and GNU).  Get a copy from the
one the BSDs, if you want to use it.

--
Måns Rullgård
mru@kth.se





[ Post a follow-up to this message ]



    Re: strtok vs split  
GVK


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-24-04 07:34 AM

Dragan Cvetkovic wrote:
> Strsep?
>
> % man strsep
> No manual entry for strsep.
>
> % uname -sr
> SunOS 5.10
>
STRSEP(3)                  Linux Programmer’s Manual                 STRSEP(
3)

NAME
strsep - extract token from string

SYNOPSIS
#include <string.h>

char *strsep(char **stringp, const char *delim);

DESCRIPTION
If  *stringp is NULL, the strsep() function returns NULL and does noth-
ing else. Otherwise, this function finds the first token in the  string
*stringp,  where  tokens  are delimited by symbols in the string delim.
This token is terminated with a  ‘\0’  character  (by  overwriting  the
delimiter) and *stringp is updated to point past the token.  In case no
delimiter was found, the  token  is  taken  to  be  the  entire  string
*stringp, and *stringp is made NULL.

RETURN VALUE
The  strsep()  function  returns  a  pointer  to the token, that is, it
returns the original value of *stringp.

NOTES
The strsep() function was introduced as  a  replacement  for  strtok(),
since  the  latter  cannot handle empty fields.  However, strtok() con-
forms to ANSI-C and hence is more portable.

BUGS
This function suffers from the same problems as strtok().  In  particu-
lar, it modifies the original string. Avoid it.

CONFORMING TO
BSD 4.4

SEE ALSO
index(3),   memchr(3),  rindex(3),  strchr(3),  strpbrk(3),  strspn(3),
strstr(3), strtok(3)

GNU                               1993-04-12                         STRSEP(
3)







[ Post a follow-up to this message ]



    Re: strtok vs split  
Ian Zimmerman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-01-04 04:34 AM


John> Is there a C-language equivalent for Java's String.split()?
John> strtok() kind of sucks: it doesn't quite the same thing, it
John> overwrites its arg and it keeps track of stuff secretly between
John> call to call.  There has *got* to be a better way. UNIX/C gurus,
John> any ideas?

I had a full C implementation of split(), but threw it away when I got a
new machine.  As you can imagine, it was tricky, calling realloc() many
times.  Now I think when I _really_ need split (and routines like strspn
won't work) it's time to switch to another language.

--
Nothing can be explained to a stone.
Or to a stoned person, either.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:24 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register