Thread: Removing parts of a string...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Removing parts of a string...

    How do i remove a character from a string by using it's position?

    In my encryption algorithm it has to pad the data if it is not a factor of the 128-bit block size. I want to remove the padding in the decryption but it will not let me do this:
    Code:
    ...
    string.at(i) = "";
    ...
    I know there's an .erase() function but i dont know if that's the way to do it.


    Thanks for the help!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I believe erase takes an iterator. If so, and you only have a position, just add the position to the begin() iterator:
    Code:
    str.erase(str.begin() + i);
    There might be better options if you are erasing multiple characters or erasing from the end of the string.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Dankeschon!

    Works grrrreaaaaaaattttttt!

    Thanks for the help!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

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, 01:02 AM
  2. printf parts from a string
    By spank in forum C Programming
    Replies: 2
    Last Post: 07-31-2007, 09:45 AM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Removing junk from end of string
    By dirkduck in forum C++ Programming
    Replies: 7
    Last Post: 05-20-2002, 01:15 PM