Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. ToUpper and ToLower part of a string in .net C++?

ToUpper and ToLower part of a string in .net C++?

Scheduled Pinned Locked Moved Managed C++/CLI
tutorialquestioncsharpc++help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TabascoSauce
    wrote on last edited by
    #1

    Thanks for looking at my question, I am wondering how I would use the ToUpper and ToLower functions on only part of a string in .net C++. For example, I converted an inputted name to all caps for the purpose of comparing it. Now I need to display the name with only the first letter capitalized. In short, I need to make "BRAD" to "Brad" Note that the inputted name is not always the same, so however you can show me how to do this has to work with any inputted name. Thanks for any help!!

    N 1 Reply Last reply
    0
    • T TabascoSauce

      Thanks for looking at my question, I am wondering how I would use the ToUpper and ToLower functions on only part of a string in .net C++. For example, I converted an inputted name to all caps for the purpose of comparing it. Now I need to display the name with only the first letter capitalized. In short, I need to make "BRAD" to "Brad" Note that the inputted name is not always the same, so however you can show me how to do this has to work with any inputted name. Thanks for any help!!

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      TabascoSauce wrote:

      with only the first letter capitalized.

      Sentence case? You can write code using SubString(), ToUpper() and ToLower(). Here it is.

      String^ ConvertToSentenceCase(String^ input)
      {
      return (input->Length > 0) ? String::Concat(input->Substring(0,1)->ToUpper(),input->Substring(1)->ToLower())
      : String::Empty;
      }

      Other methid is to use TextInfo class and work with ToTitleCase method. Here it is

      String^ ConvertToSentenceCase(String^ input)
      {
      using namespace System::Threading;
      return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(input);
      }

      Hope that helps :)

      Navaneeth How to use google | Ask smart questions

      T 1 Reply Last reply
      0
      • N N a v a n e e t h

        TabascoSauce wrote:

        with only the first letter capitalized.

        Sentence case? You can write code using SubString(), ToUpper() and ToLower(). Here it is.

        String^ ConvertToSentenceCase(String^ input)
        {
        return (input->Length > 0) ? String::Concat(input->Substring(0,1)->ToUpper(),input->Substring(1)->ToLower())
        : String::Empty;
        }

        Other methid is to use TextInfo class and work with ToTitleCase method. Here it is

        String^ ConvertToSentenceCase(String^ input)
        {
        using namespace System::Threading;
        return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(input);
        }

        Hope that helps :)

        Navaneeth How to use google | Ask smart questions

        T Offline
        T Offline
        TabascoSauce
        wrote on last edited by
        #3

        Hey thanks for the help! Sadly I am still having issues, after I tried to build it the build log gives me the error: "1>.\TempConverter.cpp(37) : error C2440: 'return' : cannot convert from 'System::String ^' to 'int' 1> No user-defined-conversion operator available, or 1> There is no context in which this conversion is possible Here's the block of code I have your second suggestion in (yes I am very, very new to programming, I'm trying to overachieve on an assignment in my online class):

        //Determining student access and calculating desired conversion 
        if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") != 0)
        {
        	//Display no-access message & end program 
        	Console::WriteLine("Sorry, you have insufficient rights to access to this program");
        	Console::Write("Please enter 1 to end the program: ");
        		endProgram = Convert::ToInt16(Console::ReadLine());
        }
        else
        {
        	//Greeting and user input 
        	if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") == 0)
        	{
        		**using namespace System::Threading;
         return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(name);
        	Console::WriteLine("Hello ", initial->ToUpper() , ". ", name);**
        	Console::Write("Are you converting from celsius or fahrenheit?: ");
        	tempr = Convert::ToString(Console::ReadLine()->ToLower());
        	}
        

        I'm trying to get it to write something like "Hello M. Beta" Feel free to point anything else I've done wrong (to an expert this probably looks horrible). Again thanks for your time and anymore help you can give me!

        modified on Sunday, February 15, 2009 6:31 PM

        N 1 Reply Last reply
        0
        • T TabascoSauce

          Hey thanks for the help! Sadly I am still having issues, after I tried to build it the build log gives me the error: "1>.\TempConverter.cpp(37) : error C2440: 'return' : cannot convert from 'System::String ^' to 'int' 1> No user-defined-conversion operator available, or 1> There is no context in which this conversion is possible Here's the block of code I have your second suggestion in (yes I am very, very new to programming, I'm trying to overachieve on an assignment in my online class):

          //Determining student access and calculating desired conversion 
          if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") != 0)
          {
          	//Display no-access message & end program 
          	Console::WriteLine("Sorry, you have insufficient rights to access to this program");
          	Console::Write("Please enter 1 to end the program: ");
          		endProgram = Convert::ToInt16(Console::ReadLine());
          }
          else
          {
          	//Greeting and user input 
          	if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") == 0)
          	{
          		**using namespace System::Threading;
           return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(name);
          	Console::WriteLine("Hello ", initial->ToUpper() , ". ", name);**
          	Console::Write("Are you converting from celsius or fahrenheit?: ");
          	tempr = Convert::ToString(Console::ReadLine()->ToLower());
          	}
          

          I'm trying to get it to write something like "Hello M. Beta" Feel free to point anything else I've done wrong (to an expert this probably looks horrible). Again thanks for your time and anymore help you can give me!

          modified on Sunday, February 15, 2009 6:31 PM

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Aah, you copied my code to a wrong place. Try this

          String^ ConvertToSentenceCase(String^ input)
          {
          using namespace System::Threading;
          return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(input);
          }

          if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") == 0)
          {
          using namespace System::Threading;
          name = ConvertToSentenceCase(name);
          Console::WriteLine("Hello ", initial->ToUpper() , ". ", name);
          // rest of the code
          }

          :)

          Navaneeth How to use google | Ask smart questions

          T 1 Reply Last reply
          0
          • N N a v a n e e t h

            Aah, you copied my code to a wrong place. Try this

            String^ ConvertToSentenceCase(String^ input)
            {
            using namespace System::Threading;
            return Thread::CurrentThread->CurrentCulture->TextInfo->ToTitleCase(input);
            }

            if (name->CompareTo("ALPHA" || "BETA" || "GAMMA") == 0)
            {
            using namespace System::Threading;
            name = ConvertToSentenceCase(name);
            Console::WriteLine("Hello ", initial->ToUpper() , ". ", name);
            // rest of the code
            }

            :)

            Navaneeth How to use google | Ask smart questions

            T Offline
            T Offline
            TabascoSauce
            wrote on last edited by
            #5

            Ahhh, Ok I understand now. Thanks for the help! After I busted through like 100 other errors I had in my program I finally got it to work. You're a lifesaver, have a good day!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups