Click here to Skip to main content
13,707,322 members

ATL / WTL / STL

 
GeneralRe: std::string Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX21-Jul-05 23:46
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX21-Jul-05 23:46 
GeneralRe: std::string Pin
Christian Graus22-Jul-05 11:52
memberChristian Graus22-Jul-05 11:52 
GeneralRegular Expressions Pin
Kevin McFarlane23-Jul-05 1:17
memberKevin McFarlane23-Jul-05 1:17 
GeneralRe: Regular Expressions Pin
Christian Graus23-Jul-05 2:46
memberChristian Graus23-Jul-05 2:46 
GeneralRe: Regular Expressions Pin
Kevin McFarlane23-Jul-05 3:43
memberKevin McFarlane23-Jul-05 3:43 
GeneralRe: Regular Expressions Pin
Christian Graus23-Jul-05 10:58
memberChristian Graus23-Jul-05 10:58 
GeneralRe: std::string - HELP Pin
LCI25-Jul-05 4:35
memberLCI25-Jul-05 4:35 
GeneralRe: std::string - HELP Pin
Roland Pibinger25-Jul-05 13:08
memberRoland Pibinger25-Jul-05 13:08 
LCI wrote:
for (size_type i = CHAR_INDEX;AnyString[i]== MySpace; i--)
AnyString.erase(i,1);
The above source only works when stripping one space, like from
"2003 " to "2003".
If i have "2003 ", it does not work. Can anyone tell me what i am doing wrong here?


You probably want a 'trim_back()' function. It must also work for 'unusual' cases like empty strings and strings that contain only white space. Also note that string::size_type is unsigned (cannot be less than 0).

#include <string>
#include <iostream>

std::string& trim_back (std::string& str)
{
 using namespace std; 
 while (str.size()) {
  if (isspace (str[str.size()-1])) {
   str.erase(str.size()-1);
  } else {
   break;
  }
 }
 return str;
}


int main()
{
 using namespace std;

 string test ("2003     "),
  whitespaceOnly (" \n\t"),
  empty;

 cout  << '|' << trim_back(test) << '|' << endl;
 cout  << '|' << trim_back(whitespaceOnly) << '|' << endl;
 cout  << '|' << trim_back(empty) << '|' << endl;

 return 0;
}

GeneralRe: std::string - HELP Pin
Rob Caldecott26-Jul-05 21:08
memberRob Caldecott26-Jul-05 21:08 
GeneralRe: std::string - HELP Pin
Kevin McFarlane30-Jul-05 23:38
memberKevin McFarlane30-Jul-05 23:38 
GeneralRe: std::string - HELP Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX31-Jul-05 23:46
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX31-Jul-05 23:46 
GeneralRe: std::string - HELP Pin
Kevin McFarlane1-Aug-05 7:21
memberKevin McFarlane1-Aug-05 7:21 
GeneralRe: std::string - HELP Pin
Nemanja Trifunovic1-Aug-05 8:12
memberNemanja Trifunovic1-Aug-05 8:12 
GeneralRe: std::string - HELP Pin
Kevin McFarlane1-Aug-05 23:04
memberKevin McFarlane1-Aug-05 23:04 
GeneralRe: std::string - HELP Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2-Aug-05 2:19
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2-Aug-05 2:19 
GeneralRe: std::string Pin
Igor Vigdorchik25-Jul-05 9:27
memberIgor Vigdorchik25-Jul-05 9:27 
Generalusing auto_ptr Pin
kramkrish21-Jul-05 1:17
memberkramkrish21-Jul-05 1:17 
GeneralRe: using auto_ptr Pin
Nish Nishant21-Jul-05 1:41
staffNish Nishant21-Jul-05 1:41 
GeneralRe: using auto_ptr Pin
Nish Nishant21-Jul-05 1:43
staffNish Nishant21-Jul-05 1:43 
GeneralRe: using auto_ptr Pin
kramkrish22-Jul-05 3:46
memberkramkrish22-Jul-05 3:46 
GeneralRe: using auto_ptr Pin
Jörgen Sigvardsson23-Jul-05 3:21
memberJörgen Sigvardsson23-Jul-05 3:21 
GeneralRe: using auto_ptr Pin
Nish Nishant23-Jul-05 4:31
staffNish Nishant23-Jul-05 4:31 
GeneralBUG: ATL 7.0 fails if chunk size is 07ff (2047 bytes) Pin
arun140520-Jul-05 4:54
memberarun140520-Jul-05 4:54 
GeneralImporting foreign types in IDL File Pin
morenz19-Jul-05 6:49
membermorenz19-Jul-05 6:49 
GeneralRe: Importing foreign types in IDL File Pin
morenz20-Jul-05 0:54
membermorenz20-Jul-05 0:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 30 Aug 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid