Re: How to Split and join string ??

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 01/29/05


Date: Sat, 29 Jan 2005 21:20:12 +1100


"Ulrich Eckhardt" <doomster@knuut.de> wrote in message
news:3613dtF4k50g7U1@individual.net...
| Anthony Borla wrote:
| > If you wish to actually *learn* to use C++ I'd recommend that you write
| > such [VB-like string manip] routines yourself. You already know the
| > interface you want - I assume identical [or at least as similar as
| > possible] to the corresponding VB functions - so all you need to do is
| > use the relevant C++ facilities to implement them. I guarantee you'll
| > learn much about the C++ language by tackling this project.
|
| Right, and then throw it all away and learn the interface of provided
| string types.

Throw what away ?, and why ?

| > One approach is to use the functionailty prototyped in the <cstring>
| > header which includes the functions std::strtok, std::strcpy, and
| > std::strcat.
|
| How can you recommend to a newbie to use those, most of all strtok which is
| broken by design? That, and the use of free storage allocated via
| new/malloc including all its pitfalls?

He didn't recommend these in preference to any others.

They were merely one of the options presented (that's
how I read it). The only recommendation I see is to write
ones own version to learn.

| Anthony, I believe that YOU could do this, but there is already enough bad
| C++ code out there, and your advise won't help a beginner write reasonable
| code.

To be honest, I thought Anthony' post was quite complete
and accurate, which presented all the facts and options
available.

I especially agree with Anthony' recommendation:

    "If you wish to actually *learn* to use
     C++ I'd recommend that you write such
     routines yourself."

...and

    "* Implement the routines using all three approaches"

..., and believe this is the best way for anyone to learn.

What do you expect a student to do when he gets his first
job, and comes across 'std::strtok()' ?, Run away and hide ?

How do you expect him to maintain older code ?, and lets
not forget, there is probably *much* more 'C' code out there
than 'C++'.

What kind of programmers do you think this train of thought
would bring us ?

The OP/Student *should* learn many approaches, and only then
can s/he make an informed decision about the advantages and
disadvantages of using each available option.

| > Another approach is to use STL library functionality with std::string,
| > and std::vector or std::list being obvious candidates for use, together
| > with the relevant iterator(s) or algorithm(s).
| >
| > Yet another approach is to use boost library functionality:
| >
| > http://www.boost.org/libs/libraries.htm
| >
| > Look for the 'tokenizer' link.
|
| Now this sounds much more sane.

It's just another option that was provided, but why do
you think that this is so sane ?

Imo, I would put this at the end of my list of things
to teach. As it stands, it just about takes an eternity
to learn the Standard Library effectively, given how vast
it is, let alone worrying about third party libraries.

Don't get me wrong, because I am a great believer in the
"C++ Standard Library", but I also recognise that to become
an *effective* programmer, you *need* to understand lower
level constructs as well, and the old 'C' functions are no
exception.

Cheers.
Chris Val



Relevant Pages

  • Re: I found my soul mate here.I am so happy!
    ... >> I've found my lover here so I recommend it to you. ... >> good luck there. ... Anthony, is that you? ...
    (rec.arts.comics.strips)
  • Re: Proof of twin-prime conjecture?
    ... Reading this proof reminds me that I know little or no analytic number theory. ... Can anyone recommend a good book? ... On 28 May 2004, Anthony J. Natoli wrote: ...
    (sci.math)
  • Re: raid controllers and suse9.1
    ... Anthony wrote: ... > I am looking to get a raid controller for my suse9.1 box. ... > Can anyone recommend a card that is affordable and that works? ...
    (alt.os.linux.suse)
  • Re: Book Recommendation
    ... Anthony writes: ... > real intimidating, but im guess im going to have to stick in there. ... I'd say read the stuff on language issues, skim the stuff on libraries ... etc. That's what I did when learning Python (in sharp ...
    (comp.lang.python)
  • Re: Shareware applications protected
    ... Some time ago I've avaluated some libraries for application protection. ... of them has been SerialShield which I can not recommend. ... floating licenses, locking licenses to hardware etc etc. ...
    (borland.public.delphi.thirdpartytools.general)