Topic: uppercase


Author: Olivier Mandavy <mandavy@alpes-net.fr>
Date: 1996/10/31
Raw View
hi,

i would like to know how to convert a string, declare with the stl, in
uppercase or lowercase ?
with the string type in the borland classlib, there is .lower() and
.upper() functions.

thank you !

Olivier
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/10/31
Raw View
Olivier Mandavy <mandavy@alpes-net.fr> writes:

>i would like to know how to convert a string, declare with the stl, in
>uppercase or lowercase ?

Given the declaration

 string s;

the code

 transform(s.begin(), s.end(), s.begin(), my_toupper);

where my_toupper is defined by

 #include <ctype.h>
 inline unsigned char my_toupper(unsigned char c) { return toupper(c); }

will do the trick.  Or alternately you could use

 for_each(s.begin(), s.end(), make_upper);

where make_upper is defined by

 #include <ctype.h>
 inline void make_upper(char &c) { c = toupper((unsigned char) c); }

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]