string parsing

This is a discussion on string parsing within the C++ Programming forums, part of the General Programming Boards category; forgive me if this is already posted elsewhere, but i don't really know where to look. does anyone know of ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    719

    string parsing

    forgive me if this is already posted elsewhere, but i don't really know where to look. does anyone know of any online resource that goes over string manipulation in depth (particularly parsing)?.....

    (a tiny bit of subject) is there a awk/sed like library for c++?

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    There's an online book on parsing that I've not read. But you can use flex and bison. http://www.gnu.org/software/flex/
    http://www.gnu.org/software/bison/bison.html

    awk/sed do regular expressions. There are libraries out there that do that such gnu's regex and boost's regular expression library. I don't have any experience using them though.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i'll check it out...but i guess i should have specified that i want it to work on windows too...

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i don't have a compiler handy right now, my workstations in use for the next couple hours, but is this ok?

    string s("2+3");
    string::size_type = s.find(("-" || "+" || "*" || "/"), 0);

    in need to extract the sign and the 'term' (includes / and *) that follows. so i need the index of FIRST operator and the index of NEXT. then copy the substring from FIRST to NEXT into a new string. FIRST = NEXT; repeat until string::npos; is there a way to do this without some serious conditional statements?
    Last edited by misplaced; 09-29-2004 at 11:51 PM.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Look into C++'s sstream.
    What is C++?

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    flex and bison are probably overkill for what you are trying to do, but you can use them on windows.

    If you just what to determine if a string contains an element, use std::find. For example,
    Code:
    if (std::find(s.begin(), s.end(), '+') != s.end()) {
    
    }

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    no....i need to find the index of those characters....

    s.find_first_of("+-*/") is my solution

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. String parsing
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 07-03-2008, 05:06 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

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