Ver Mensaje Individual
  #7 (permalink)  
Antiguo 06/04/2015, 05:59
ecfisa
 
Fecha de Ingreso: julio-2012
Mensajes: 133
Antigüedad: 11 años, 9 meses
Puntos: 22
Respuesta: Primera letra de cada palabra en mayúscula (String)

Hola.
Cita:
Iniciado por JarolGarcia Ver Mensaje
una pregunta....y si coloco mas espacios en blanco? ejemplo:
esto___es__un_____mensaje
Esto___Es__Un_____Mensaje
haber si pueden ayudarme
Código C++:
Ver original
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. void firstUpper ( string& str ) {
  8.   str[0] = ::toupper( str[0] );
  9.   for ( string::iterator it = str.begin(); it != str.end(); it++ )
  10.     if ( *it == ' ' )
  11.       *( it+1 ) = ::toupper( *( it+1 ) );
  12. }
  13. ...
Ejemplo de llamada:
Código C++:
Ver original
  1. ...
  2.  
  3. int main() {
  4.   string s = "prueba de   texto, primer  letra  de    cada    palabra  en   mayuscula";
  5.  
  6.   firstUpper( s );
  7.  
  8.   cout << s;
  9.  
  10.   return 0;
  11. }

Saludos.

Última edición por ecfisa; 06/04/2015 a las 06:09