PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > chopping strings
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
chopping strings

Réponse
 
LinkBack Outils de la discussion
Vieux 17/10/2007, 16h06   #1
djm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut chopping strings

hello everyone. ive a string with a blank space at the start
for eg:
string str=" c++ rocks!";
how can i chop of that blank space of the string and display?
thanks

  Réponse avec citation
Vieux 17/10/2007, 16h12   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: chopping strings

djm wrote:
> hello everyone. ive a string with a blank space at the start
> for eg:
> string str=" c++ rocks!";
> how can i chop of that blank space of the string and display?


Find the first character that isn't a space and erase all chars
between the start of the string and that character. RTFM on how
to find and how to erase.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  Réponse avec citation
Vieux 17/10/2007, 20h28   #3
Jim Langston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: chopping strings

"djm" <djmlog103@gmail.com> wrote in message
news:1192633612.268469.31450@q5g2000prf.googlegrou ps.com...
> hello everyone. ive a string with a blank space at the start
> for eg:
> string str=" c++ rocks!";
> how can i chop of that blank space of the string and display?
> thanks


This is what I use.

std::string trim( const std::string& text, const char TrimChar = ' ' )
{
std::string::size_type First = text.find_first_not_of(TrimChar);
if ( First == std::string::npos )
return "";
return text.substr( First, text.find_last_not_of(TrimChar) - First +
1);
}

Note it will trim any spaces (or specified character) from both the front
and end of the string.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h48.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07309 seconds with 11 queries