C++ : Function to convert lower case string to upper case

Поделиться
HTML-код
  • Опубликовано: 9 янв 2025

Комментарии • 37

  • @quanduong3390
    @quanduong3390 4 года назад +2

    If you are reading this, thank you!! your code is so much simplier than the one I used to use.

  • @clairelaam5408
    @clairelaam5408 9 лет назад +7

    A big like for you !!!! Your codes are much more useful than the other codes on web!!! The other codes on web are just too complex!

  • @zNTaTG2b
    @zNTaTG2b 9 лет назад +1

    Awesome dude, really helps me out, It's nice to see this from a professional and not from a noob...

  • @dr.dimplesoni3105
    @dr.dimplesoni3105 6 лет назад +1

    Thank you so much . I couldn't find this anywhere on the web and I needed it so dearly for my project !

  • @danielk.6700
    @danielk.6700 3 года назад +2

    Thanks a million. This just saved me from so much work.

  • @deviladvocate21
    @deviladvocate21 6 лет назад +6

    This doesn't show you how to make the function itself, so I'll show you a way how to do it whilst making everything yourself. It's fairly complex for what it does, and feel free to ask questions, but in short, it checks for each character in the string, and if its ASCII value is greater than 96 ('a' and above) and less than 123 ('z' and below), then it will take 32 from its value (if you look on the ASCII table, uppercase equivalents are 32 less in decimal) and add that to the string we made earlier; if not, then it will simply add the character to the string as is, as changing the value of a character that isn't a lowercase letter will make it a different character that is nothing to do with what it was before (again, look at the ASCII table and you'd see why).
    Make sure to include the header whilst doing this, or you won't be able use std::string.
    #include
    using namespace std;
    string toUpper(string str) {
    string newString;
    for (int i = 0; i < str.length(); i++) {
    if (str.at(i) > 96 && str.at(i) < 123) {
    newString += str.at(i) - 32;
    } else {
    newString += str.at(i);
    }
    }
    return newString;
    }

    • @deviladvocate21
      @deviladvocate21 6 лет назад

      Also, I'm fairly new to C++ programming, but I've had experience in some other programming languages, and I have tested it and it has worked so far. If you're working with other datatypes (like char* or char[]) then I wouldn't imagine that the function would work, but you should probably use std::string instead anyway, instead of the C alternatives.

    • @deviladvocate21
      @deviladvocate21 6 лет назад +3

      Also again, you can alter this to make a toLower() function.
      Simply replace:
      if (str.at(i) > 96 && str.at(i) < 123) {
      with:
      if (str.at(i) > 64 && str.at(i) < 91) {
      and replace:
      newString += str.at(i) - 32;
      with:
      newString += str.at(i) + 32;
      You might want to look up the ASCII table and find out how it works, note that I'm using decimal ASCII values, not hexadecimal, although it should still work if you convert the numbers to hexadecimal, decimal is much more readable (as that's what you count with)

  • @ahmedn8732
    @ahmedn8732 8 лет назад +2

    This video saved me hours of work. Thanks!!!

  • @alexandruteodor3585
    @alexandruteodor3585 4 года назад +2

    It was so simple to do it! :)) Thank you!

  • @amourvido8027
    @amourvido8027 3 года назад +1

    Now i have peace, thanks man!

  • @007JackTR
    @007JackTR 3 года назад +1

    Awesome, thanks a million!!!!

  • @DanTheMannn
    @DanTheMannn 9 лет назад +4

    Listen man, I'm gonna comment on this video, because you helped me save my semester. Basically the teacher said she'd give me my 10 missing points to pass, if I could come up with a toUpper or toLower solution. THANK YOU!

  • @CarolinaMadness
    @CarolinaMadness 8 лет назад

    Thank you. You the REAL MVP

  • @stemic349
    @stemic349 5 лет назад +1

    Gracias!! Me sirvió muchisimo.

  • @GabrielSilva-ce5eb
    @GabrielSilva-ce5eb 2 года назад +1

    Thanks

  • @JesusGarcia-qy9zx
    @JesusGarcia-qy9zx 8 лет назад +1

    i try to run it but i got an error,a red crooked line under the { void convert. any advice?

  • @AlejoriasA
    @AlejoriasA 4 года назад +1

    And what if one needs to apply the same to *char* variables?

    • @muzamilzaman7463
      @muzamilzaman7463 2 года назад

      You need to get array of char and then index

  • @UFG_SoulTaker
    @UFG_SoulTaker 5 лет назад +2

    if I want to upper two strings in a for loop, how could I do that? Also just the first letter tho, thanks.

  • @cotogames9586
    @cotogames9586 6 лет назад

    this code didnt work for me... what IDE and what compiler are you using?

  • @muzamilzaman7463
    @muzamilzaman7463 2 года назад

    Suppose i want to make huge size of Alphabet ??? What program would be that

  • @christoschristou4526
    @christoschristou4526 7 лет назад

    Can someone explain me what line 4-21 mean?I am new at programming

  • @falveyy
    @falveyy 6 лет назад +1

    OMG, thanks!

  • @Psych0tikk
    @Psych0tikk 8 лет назад +5

    Sucks that tolower/toupper doesn't work on strings. We have to resort to this crap...

  • @ezioauditore7636
    @ezioauditore7636 6 лет назад

    Someone explain what string& does. Not in advanced terms such as 'pointers' and shit cause that assume I know what those are in the first place.

  • @sachiuddin8295
    @sachiuddin8295 5 лет назад +1

    Thank you omg

  • @robertburns464
    @robertburns464 8 лет назад

    This function does not work for me when string involves both types of letters. Ex: HeLlo

  • @ahdkarman5932
    @ahdkarman5932 5 лет назад +1

    Thaaaaanks a lot

  • @stevefrt9495
    @stevefrt9495 8 лет назад

    Thanks you so much

  • @harishankar8905
    @harishankar8905 8 лет назад

    This shows "use of undeclared identifier 'i' "

  • @AppleSecurity
    @AppleSecurity 6 лет назад

    YOU ARE GOOD

  • @ggggggggggalex
    @ggggggggggalex 9 лет назад

    Praise the sun !!!

  • @munisaashurova2542
    @munisaashurova2542 4 года назад

    thank you very much.Great