2 Replies - 437 Views - Last Post: 27 January 2009 - 10:52 AM

#1 Vextor   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 313
  • Joined: 22-May 02

C++ String Class, Simple Parsing Function

Posted 29 September 2006 - 11:30 PM

Description: A function that recieves a string and a char and returns a string* in which all occurences of that char are removed from the string.
//Vextor aka Brandon W.
//September 30, 2006
//A simple string parser

/*Because this snippet is simple it's application is limited. However with
a bit of creative modification this function may be used for a number
of tasks. Or not, I don't know...*/


#include <string>


//.... 

string *ParseThisString(string *s, char *c)
{
     int stringsize = s->size();
     string tempstring;
     
     while(s->find(*c) != string::npos)
     {
        int loc = s->find(*c);
        tempstring = s->substr(0, (loc-1)) + s->substr((loc+1),s->length());
     }
        return &tempstring;   
}




Is This A Good Question/Topic? 0
  • +

Replies To: C++ String Class, Simple Parsing Function

#2 pramaku   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 06-May 08

Re: C++ String Class, Simple Parsing Function

Posted 06 May 2008 - 12:30 AM

hey this code is not working... any one had tried it...
Was This Post Helpful? 0
  • +
  • -

#3 greatdragon   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 08-November 06

Re: C++ String Class, Simple Parsing Function

Posted 27 January 2009 - 10:52 AM

Did you actually RUN this code before posting it on the Internet? Change line 23 to this (or else it will delete more characters than it should): tempstring = s->substr(0, (loc)) + s->substr((loc+1),s->length()); Then between lines 23 and 24, add this line or else it will be in an endless loop: *s = tempstring;
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1