substract character from string?

This is a discussion on substract character from string? within the C++ Programming forums, part of the General Programming Boards category; Is there a function to substract certain charakters from a string? My string contains masses of ';' between various characters ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    15

    Question substract character from string?

    Is there a function to substract certain charakters from a string?

    My string contains masses of ';' between various characters that I want to process.

    Thanx.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    So you want everything in the string besides the ';'?
    Sounds like a job for strtok. Google found me this: http://www.opengroup.org/onlinepubs/...sh/strtok.html

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Here's a program :

    Code:
    #include <string>
    #include <iostream>
    using std::string;
    
    string strremove(const string& str, char rm)
    {
      string strnew;
      for (string::size_type p = 0;p < str.length(); ++p)
        if (str[p] != rm)
           strnew += str[p];
      return strnew; 
    }
    
    int main()
    {
       string foo = ";;;;sang-;;;drax;;";
       std::cout << strremove(foo,';');
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    15
    I already tried strtok. It had Problems returning tokens like ' - + / '. Any Idea, why?

    Code:
    lkv_Pointer = strtok (lkv_String, ";");
    while (lkv_Pointer != NULL)
    {
    	cout << lkv_Pointer << endl;
    	lkv_Pointer = strtok (NULL, ";");
    }
    My lkv_String looks something like this:
    Code:
    ;;;;;;;;;;;;-20;;;;;;+60;;;;;;;;-30;;;;;;;;

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    15
    Sorry! Ignore my last post - found mistake.
    Thanks for all replies!

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    you're using string classes, right? if you search google i think there's a list of member functions for that, some which may help you here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 02:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

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