Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10021

Re: Best way to tokenize in String

From "Paul" <pchristor@yahoo.co.uk>
Newsgroups comp.lang.c++
Subject Re: Best way to tokenize in String
Date 2011-09-10 11:32 +0100
Organization Netfront http://www.netfront.net/
Message-ID <j4febp$1ve4$1@adenine.netfront.net> (permalink)
References <507fe825-0df5-4099-bacd-02275460e729@u20g2000yqj.googlegroups.com> <9d030kFn7lU2@mid.individual.net> <dfa74db2-9825-42ea-bffc-eff58c4ef50d@o9g2000vbo.googlegroups.com> <j4ev39$o1e$1@dont-email.me>

Show all headers | View raw


"red floyd" <no.spam.here@its.invalid> wrote in message 
news:j4ev39$o1e$1@dont-email.me...
> On 9/9/2011 10:30 PM, Paul wrote:
>> On Sep 10, 4:14 am, Ian Collins<ian-n...@hotmail.com>  wrote:
>>> On 09/10/11 02:25 PM, sravanreddy001 wrote:
>>>
>>>> Hi,
>>>> what is the efficient way to tokenize the string and splitting into
>>>> words based on the delimiter?
>>>
>>> The simplest way is to create an istringstream from the string and
>>> stream out the words.
>>>
>> But is that the most efficient way?
>
> Screw "efficiency".  The amount of time parsing should be minimal
> compared to either your I/O or processing time.  Until you benchmark
> and show that the tokenizing is a bottleneck, go for the simplicity.
>
Yeah I know efficiency wouldn't be mega important in many cases but the OP 
did specifically ask about something more efficient than strtok.

Anyway you can't really do anything other than loop through the string 
testing each char against a delimiter. Any gains in efficiency are probably 
in the way the data is input/output where:
input(file read lines?) ---> tokenizer function ---> output(further 
processing?)

When you find a token what do you do with it; store it or send it for 
further processing?
The design of the function needs to fit the programs needs i.e: return 
value, argument types, does it throw exceptions, is it a template, is it a 
class member etc etc. 


--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to tokenize in String sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-09 19:25 -0700
  Re: Best way to tokenize in String Ian Collins <ian-news@hotmail.com> - 2011-09-10 15:14 +1200
    Re: Best way to tokenize in String Paul <pchristor@yahoo.co.uk> - 2011-09-09 22:30 -0700
      Re: Best way to tokenize in String red floyd <no.spam.here@its.invalid> - 2011-09-09 23:11 -0700
        Re: Best way to tokenize in String "Paul" <pchristor@yahoo.co.uk> - 2011-09-10 11:32 +0100
      Re: Best way to tokenize in String Ben Cottrell <email@address.invalid> - 2011-09-10 13:05 +0100
        Re: Best way to tokenize in String Paul <pchristor@yahoo.co.uk> - 2011-09-10 08:25 -0700
  Re: Best way to tokenize in String Leigh Johnston <leigh@i42.co.uk> - 2011-09-10 13:15 +0100
  Re: Best way to tokenize in String Asger-P <junk@asger-p.dk> - 2011-09-10 14:54 +0200
  Re: Best way to tokenize in String Moshbear dot Net <moshbear.net@gmail.com> - 2011-09-10 22:46 -0700

csiph-web