Click here to Skip to main content
13,764,280 members

ATL / WTL / STL

 
GeneralRe: std::string Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX22-Jul-05 0:46
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX22-Jul-05 0:46 
GeneralRe: std::string Pin
Christian Graus22-Jul-05 12:52
protectorChristian Graus22-Jul-05 12:52 
GeneralRegular Expressions Pin
Kevin McFarlane23-Jul-05 2:17
memberKevin McFarlane23-Jul-05 2:17 
GeneralRe: Regular Expressions Pin
Christian Graus23-Jul-05 3:46
protectorChristian Graus23-Jul-05 3:46 
GeneralRe: Regular Expressions Pin
Kevin McFarlane23-Jul-05 4:43
memberKevin McFarlane23-Jul-05 4:43 
GeneralRe: Regular Expressions Pin
Christian Graus23-Jul-05 11:58
protectorChristian Graus23-Jul-05 11:58 
GeneralRe: std::string - HELP Pin
LCI25-Jul-05 5:35
memberLCI25-Jul-05 5:35 
GeneralRe: std::string - HELP Pin
Roland Pibinger25-Jul-05 14:08
memberRoland Pibinger25-Jul-05 14: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
26-Jul-05 22:08
suss26-Jul-05 22:08 
GeneralRe: std::string - HELP Pin
Kevin McFarlane31-Jul-05 0:38
memberKevin McFarlane31-Jul-05 0:38 
GeneralRe: std::string - HELP Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1-Aug-05 0:46
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1-Aug-05 0:46 
GeneralRe: std::string - HELP Pin
Kevin McFarlane1-Aug-05 8:21
memberKevin McFarlane1-Aug-05 8:21 
GeneralRe: std::string - HELP Pin
Nemanja Trifunovic1-Aug-05 9:12
memberNemanja Trifunovic1-Aug-05 9:12 
GeneralRe: std::string - HELP Pin
Kevin McFarlane2-Aug-05 0:04
memberKevin McFarlane2-Aug-05 0:04 
GeneralRe: std::string - HELP Pin
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2-Aug-05 3:19
memberXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2-Aug-05 3:19 
GeneralRe: std::string Pin
Igor Vigdorchik25-Jul-05 10:27
memberIgor Vigdorchik25-Jul-05 10:27 
Generalusing auto_ptr Pin
kramkrish21-Jul-05 2:17
memberkramkrish21-Jul-05 2:17 
GeneralRe: using auto_ptr Pin
Nish Nishant21-Jul-05 2:41
sitebuilderNish Nishant21-Jul-05 2:41 
GeneralRe: using auto_ptr Pin
Nish Nishant21-Jul-05 2:43
sitebuilderNish Nishant21-Jul-05 2:43 
GeneralRe: using auto_ptr Pin
kramkrish22-Jul-05 4:46
memberkramkrish22-Jul-05 4:46 
GeneralRe: using auto_ptr Pin
Jörgen Sigvardsson23-Jul-05 4:21
memberJörgen Sigvardsson23-Jul-05 4:21 
GeneralRe: using auto_ptr Pin
Nish Nishant23-Jul-05 5:31
sitebuilderNish Nishant23-Jul-05 5:31 
GeneralBUG: ATL 7.0 fails if chunk size is 07ff (2047 bytes) Pin
arun140520-Jul-05 5:54
memberarun140520-Jul-05 5:54 
GeneralImporting foreign types in IDL File Pin
morenz19-Jul-05 7:49
membermorenz19-Jul-05 7:49 
GeneralRe: Importing foreign types in IDL File Pin
morenz20-Jul-05 1:54
membermorenz20-Jul-05 1: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.181113.4 | Last Updated 16 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid