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. C#
  4. How to Change the string to Upper Casing

How to Change the string to Upper Casing

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
8 Posts 6 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.
  • Z Offline
    Z Offline
    zxc89
    wrote on last edited by
    #1

    Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!

    S L E G 4 Replies Last reply
    0
    • Z zxc89

      Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!

      S Offline
      S Offline
      Sebastian Schneider
      wrote on last edited by
      #2

      OK, just to make sure: SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase or SomeTextInUpperCase -> SOME_TEXT_IN_UPPER_CASE? Subject-Line + Content = Not entirely sure what you want.

      Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

      Z 1 Reply Last reply
      0
      • Z zxc89

        Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        zxc89 wrote:

        I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help..

        To just make the string lowercase you can you string.ToLower(). But to format it the way you want it, you'd need to write your own algorithm. But it's really easy, if all uppercase strings have the format you mentioned. regards

        1 Reply Last reply
        0
        • S Sebastian Schneider

          OK, just to make sure: SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase or SomeTextInUpperCase -> SOME_TEXT_IN_UPPER_CASE? Subject-Line + Content = Not entirely sure what you want.

          Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

          Z Offline
          Z Offline
          zxc89
          wrote on last edited by
          #4

          Hi Sebastian, i need the following only.. SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase Plz help me to do this one...Thanks..

          A 1 Reply Last reply
          0
          • Z zxc89

            Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!

            E Offline
            E Offline
            eggsovereasy
            wrote on last edited by
            #5

            You need to use .Split() to divide the original string into a string array (use '_' as the character to split on). Then in each element of the newly created array use the index on the string to get the first letter, then use .SubString to get the remaining characters in the element and make them lower case (.ToLower()), then you can move on to the next element. Use a StringBuilder to concatonate it.

            1 Reply Last reply
            0
            • Z zxc89

              Hi Sebastian, i need the following only.. SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase Plz help me to do this one...Thanks..

              A Offline
              A Offline
              Alex UEA
              wrote on last edited by
              #6

              not elegant but...

              private static String mixCase(string inString)
              {
              String outString = inString.Substring(0, 1).ToUpper();
              inString = inString.Substring(1).ToLower();
              String lastChar = "";
              for (int iIndex = 0; iIndex < inString.Length; iIndex++)
              {
              if (iIndex > 1)
              {
              lastChar = inString.Substring(iIndex - 1, 1);
              }
              if (lastChar.Equals("_"))
              {
              outString = outString.Substring(0, outString.Length - 1);
              outString += inString.Substring(iIndex, 1).ToUpper();
              }
              else
              {
              outString += inString.Substring(iIndex, 1);
              }
              }
              return outString;
              }

              Z 1 Reply Last reply
              0
              • Z zxc89

                Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Here's a neat solution. :)

                private string Camelize(string text) {
                return System.Text.RegularExpressions.Regex.Replace("_" + text, "(_.|.)", delegate(System.Text.RegularExpressions.Match match) { return match.Value.Length == 2 ? match.Value.Substring(1, 1) : match.Value.ToLower(); });
                }

                --- b { font-weight: normal; }

                1 Reply Last reply
                0
                • A Alex UEA

                  not elegant but...

                  private static String mixCase(string inString)
                  {
                  String outString = inString.Substring(0, 1).ToUpper();
                  inString = inString.Substring(1).ToLower();
                  String lastChar = "";
                  for (int iIndex = 0; iIndex < inString.Length; iIndex++)
                  {
                  if (iIndex > 1)
                  {
                  lastChar = inString.Substring(iIndex - 1, 1);
                  }
                  if (lastChar.Equals("_"))
                  {
                  outString = outString.Substring(0, outString.Length - 1);
                  outString += inString.Substring(iIndex, 1).ToUpper();
                  }
                  else
                  {
                  outString += inString.Substring(iIndex, 1);
                  }
                  }
                  return outString;
                  }

                  Z Offline
                  Z Offline
                  zxc89
                  wrote on last edited by
                  #8

                  Thank u so much!!!

                  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