Convert input to lower case?

Discussion in 'C++' started by eli m, Mar 20, 2013.

  1. eli m

    eli m Guest

    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!
    eli m, Mar 20, 2013
    #1
    1. Advertising

  2. eli m

    Ian Collins Guest

    eli m wrote:
    > 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.

    --
    Ian Collins
    Ian Collins, Mar 20, 2013
    #2
    1. Advertising

  3. eli m

    James Kanze Guest

    On Wednesday, 20 March 2013 10:18:08 UTC, wrote:
    > On Wed, 20 Mar 2013 08:46:21 +0000 (UTC), Juha Nieminen


    > <> wrote:
    > >Ian Collins <> wrote:
    > >> eli m wrote:
    > >>> 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.


    > >You are assuming ASCII.


    > 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.)

    --
    James
    James Kanze, Mar 20, 2013
    #3
  4. eli m

    osmium Guest

    James Kanze wrote:
    > On Wednesday, 20 March 2013 10:18:08 UTC, wrote:
    >> On Wed, 20 Mar 2013 08:46:21 +0000 (UTC), Juha Nieminen

    >
    >> <> wrote:
    >>> Ian Collins <> wrote:
    >>>> eli m wrote:
    >>>>> 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.

    >
    >>> You are assuming ASCII.

    >
    >> 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.)


    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.
    osmium, Mar 20, 2013
    #4
  5. On 3/20/2013 11:58 AM, osmium wrote:
    >[..]
    > 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
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Mar 20, 2013
    #5
  6. eli m

    osmium Guest

    "Victor Bazarov" wrote:

    > On 3/20/2013 11:58 AM, osmium wrote:
    >>[..]
    >> 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.
    osmium, Mar 20, 2013
    #6
  7. On 3/20/2013 12:18 PM, osmium wrote:
    > "Victor Bazarov" wrote:
    >
    >> On 3/20/2013 11:58 AM, osmium wrote:
    >>> [..]
    >>> 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
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Mar 20, 2013
    #7
  8. eli m

    Stefan Ram Guest

    Victor Bazarov <> writes:
    >On 3/20/2013 11:58 AM, osmium wrote:
    >>[..]
    >> 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."
    Stefan Ram, Mar 20, 2013
    #8
  9. eli m

    Ian Collins Guest

    osmium wrote:
    > "Victor Bazarov" wrote:
    >
    >> On 3/20/2013 11:58 AM, osmium wrote:
    >>> [..]
    >>> 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 :)

    --
    Ian Collins
    Ian Collins, Mar 21, 2013
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    701
    Jürgen Exner
    Dec 7, 2004
  2. Mark
    Replies:
    3
    Views:
    566
  3. Replies:
    6
    Views:
    968
    Jim Moe
    Dec 1, 2006
  4. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,162
    Richard Bos
    Dec 14, 2004
  5. penny
    Replies:
    28
    Views:
    2,359
    Charlton Wilbur
    Mar 10, 2008
Loading...

Share This Page