Re: going through a string / char array and putting the bits in other variables

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 03/13/04


Date: Sat, 13 Mar 2004 21:19:06 GMT


"DangerD321" <dangerd321@aol.com> wrote...
> im trying to create a function which takes one line of input, either as a
> string or character array, and then reads through the string and takes
each
> word and stores it in other strings or characters, so say the line of
input
> was:
>
> Dean Steven 02/14/67
>
> and i would have a variable for first name, surname and dob set up. There
are
> more varialbes and stuff but Im tryin to do it myself I just don't know
where
> to look.

Have you tried a C++ book? If yes, which book? If not, why?

>I used just simpley if(aLine[counter] != ' ') to keep reading until a
> space but this isn't very efficient really

How do you know? Have you timed it versus some other method?

> and i was wodnering if there were
> just functions to do this sort of thing,

Yes, but essentially they just do that 'if(.. != ' ')' behind the scenes.
Take a look at 'strchr' for character arrays and 'find' for std::string.

> because some inputs like DOB will not
> always be there and i need to check. Also, it is not known how many spaces
are
> between each word.

Then you just skip them all. For std::string take a look at member
function find_first_not_of. For an array, just enumerate until you
find that it's not a space.

>
> I hope ive outlined the problem correctly, and thanks for any help,

Well, give it a shot (even if it's "inefficient"). There is a saying
among [experienced] programmers: first make it work, THEN make it fast.

Victor



Relevant Pages

  • Re: Substring
    ... Which is unfortunate because the null string will be holding on to a character array it doesn't need. ... As suggested in 2001 and 2005 Sun bug reports regarding this very behaviour of substring(...), if the implementation of substringdoes not change it would be helpful if the Javadoc for the method points out this behaviour. ...
    (comp.lang.java.programmer)
  • read bytes from file
    ... NextExecuteTime As Date ... ProcScheduler As String * 1 ... offsets and lengths contained in the TextOffset array. ... into a character array, but I have to define the character array size before ...
    (comp.lang.java.programmer)
  • Re: Possible but hackish answer
    ... It clips off that tag, and simply has a string named 'line' with the data I need, "7.874". ... I hate using those for regular control, but it's the only good way I can think of to do this. ... DecimalSwitchtakes the string and turns it into a character array c. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: select specific capture device by name
    ... > I beleive that var.bstrval has the string that I need, ... IVC_BOARD_NAME is not a BSTR. ... and points to a Unicode character array. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: How to match string for cell array strmatch() in Matlab
    ... Requires character array or cell array of strings as inputs. ... then I need to parse the textscan results using the strmatch but met ... If you just want to know if there is an 'a' but don't care where in the string it is, ...
    (comp.soft-sys.matlab)