Thread: handling strings find_first_of etc

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    handling strings find_first_of etc

    I am having headaches with a project handling large databases, its a pain in the bee-hind becuase all the data is formatted differently, its a mess and i am trying to automate tidying it up to generate some useful lists.

    The source files are all .CSV, but some of them use the - define strings with "" - method and others don't and just use the comma delimiter to demarcate fields.

    Also i have to parse names from the strings and swap them around strip out invalid symbols etc.

    The problem i am having is developing a safe or tidy way to use 'str.find_first_of etc,

    If the symbol sought is not found then the value returned can mean i then try to subseqently erase out of bounds on the string.

    What is a good way of ensuring safely using the value returned by find_first_of, or find_last_of??

    I am about to try this, is this the way to check? Even if it is thats still a pain as it has to be done on each operation required with that particular string

    Code:
    size_t pos = tempStr.find_first_of(',');
    
            if(pos != string::npos)         
            tempStr.erase(pos); //get rid of all content except the name field
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Well that worked, but always writing that line seems like a chore, but mebbe thats best way
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handling and exception handling
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 10:01 PM
  2. Windows' std::string::find_first_of error
    By g4j31a5 in forum C++ Programming
    Replies: 3
    Last Post: 03-22-2009, 11:07 PM
  3. Swapping strings in an array of strings
    By dannyzimbabwe in forum C Programming
    Replies: 3
    Last Post: 03-03-2009, 12:28 PM
  4. Replies: 2
    Last Post: 08-29-2008, 05:29 AM
  5. Help with handling strings
    By LinMach in forum C Programming
    Replies: 2
    Last Post: 04-18-2003, 04:29 PM