Convert input to lower case?

E

eli m

Hi guys, I have a program where it gets input and assigns it to a string. How do I make the input get converted into lowercase? Thanks in advance!
 
I

Ian Collins

eli said:
Hi guys, I have a program where it gets input and assigns it to a
string. How do I make the input get converted into lowercase? Thanks
in advance!

Look up std::transform and tolower.
 
J

James Kanze

tolower doesn't assume ASCII.

But it does assume single byte encodings, no UTF-8. (And of
course, it also supposes that tolower has a reasonable
definition. It won't work with German, for example, where the
lower case of "SS" may be either "ss" or "ß", depending on
context, or in some conventions of French, where the lower case
of "E" may be "é", "è", "ê", "ë" or "e", depending on context.
The idea of converting a string to lower case with a linguistic
context is non-trivial, and may not even be possible.)

More to the point, of course, there are a couple of very subtle
issues when using std::transform and tolower. You can't simply
pass the tolower from <ctype.h> to std::transform, at least if
you're iterating over char, because the tolower in <ctype.h>
results in undefined behavior when called with a char. And once
you include <locale>, you get all sorts of issues regarding
ambiguity. (And of course, you don't always know whether
<locale> has been included or not.)
 
O

osmium

James said:
But it does assume single byte encodings, no UTF-8. (And of
course, it also supposes that tolower has a reasonable
definition. It won't work with German, for example, where the
lower case of "SS" may be either "ss" or "ß", depending on
context, or in some conventions of French, where the lower case
of "E" may be "é", "è", "ê", "ë" or "e", depending on context.
The idea of converting a string to lower case with a linguistic
context is non-trivial, and may not even be possible.)

More to the point, of course, there are a couple of very subtle
issues when using std::transform and tolower. You can't simply
pass the tolower from <ctype.h> to std::transform, at least if
you're iterating over char, because the tolower in <ctype.h>
results in undefined behavior when called with a char. And once
you include <locale>, you get all sorts of issues regarding
ambiguity. (And of course, you don't always know whether
<locale> has been included or not.)

That finally answers a long term nagging question I have had.

I used to correspond with a woman in Germany. I would compose my letters in
English and send them to an instructor (who spoke with a German accent) at a
nearby university. She would translate to German and send it back to me.
One problem was she has a Mac and I had a PC. I couldn't persuade her to
use .rtf format (I thought that was the right way to approach this
situation). Anyway she used some damn Mac format thing I had to convert to
PC ese, and then make and send a hard copy to my correspondent in Germany.
My clue to whether things were going well was the ß, since it stands out
like a sore thumb. Then the ß started disappearing! I called her and asked
what was going on. She said, "Oh, the use of esset is downplayed nowadays."
Reluctantly she humored me by using the esset when sending something to me.

The upshot was I got interested in what was the glyph for the lower case ß.
So your answer is "There is none!"". So now I know. I think.
 
V

Victor Bazarov

[..]
The upshot was I got interested in what was the glyph for the lower case ß.
So your answer is "There is none!"". So now I know. I think.

Uh... The "ß" *is* the lower case. :) The *upper*case is SS.

V
 
O

osmium

Victor Bazarov said:
[..]
The upshot was I got interested in what was the glyph for the lower case
ß.
So your answer is "There is none!"". So now I know. I think.

Uh... The "ß" *is* the lower case. :) The *upper*case is SS.

Oops. Thanks, Victor.

It just *looks* so upper case. The first time I saw it I thought it was a
Greek upper case beta.

We Americans are quite insular. But you probably already knew that.
 
V

Victor Bazarov

Victor Bazarov said:
[..]
The upshot was I got interested in what was the glyph for the lower case
ß.
So your answer is "There is none!"". So now I know. I think.

Uh... The "ß" *is* the lower case. :) The *upper*case is SS.

Oops. Thanks, Victor.

It just *looks* so upper case. The first time I saw it I thought it was a
Greek upper case beta.

You're going to hate me... It's actually a *lowercase* beta. The
uppercase beta looks just like the Latin/English B.
We Americans are quite insular. But you probably already knew that.

What do they say? "All generalizations are wrong"... ;-)

V
 
S

Stefan Ram

Victor Bazarov said:
[..]
The upshot was I got interested in what was the glyph for the lower case ß.
So your answer is "There is none!"". So now I know. I think.
Uh... The "ß" *is* the lower case. :) The *upper*case is SS.

Some rule guides recommend to use »SZ« when »SS« would be ambiguous.

»Ich trinke in Massen.« I mass-drink (drink huge amounts).
»Ich trinke in Maßen.« I drink moderately.

--> "ICH TRINKE IN MASSEN."
 
I

Ian Collins

osmium said:
Victor Bazarov said:
[..]
The upshot was I got interested in what was the glyph for the lower case
ß.
So your answer is "There is none!"". So now I know. I think.

Uh... The "ß" *is* the lower case. :) The *upper*case is SS.

Oops. Thanks, Victor.

It just *looks* so upper case. The first time I saw it I thought it was a
Greek upper case beta.

We Americans are quite insular. But you probably already knew that.

Us Brits just use std::shout for our translations :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top