Exploding a string?

This is a discussion on Exploding a string? within the C++ Programming forums, part of the General Programming Boards category; I have a program that takes in a line of input, separates it into individual words, and then runs each ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    100

    Exploding a string?

    I have a program that takes in a line of input, separates it into individual words, and then runs each of those words through a method that replaces illegal characters (like ! and @) with spaces, and then inserts each word into a BST. For example, if a line of input was:

    Code:
    one TWO three@four
    What would get broken up would be:

    Code:
    one
    TWO
    three@four
    And then when the words went through my modify method, it would look like:

    Code:
    one
    two
    three four
    Notice however that "three four" is considered one word. What I need to do is break apart "three four" after the illegal characters are removed so that my word structure would now look like:

    Code:
    one
    two
    three
    four
    i.e. four nodes would be inserted, not three. Is there any way to do this?
    "I don't fail - I succeed at finding things that don't work"
    Website Promotion Techniques @AbstractPromotion.com

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why don't you run the "replace illegal chars" before you split the words out?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    A way you could replace characters is this (str being the string):
    Code:
    replace (str.begin(), str.end(), '@', ' ');

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21