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. using toupper to uppercase an array index

using toupper to uppercase an array index

Scheduled Pinned Locked Moved C#
databasedata-structuresquestion
5 Posts 5 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.
  • D Offline
    D Offline
    doughyi8u
    wrote on last edited by
    #1

    I'm trying to uppercase the second word in a string of two words (a first and last name).

    int index;
    string name = "Jeffrey steinberg";

    index = name.IndexOf(' ');
    name = name[index + 1].ToUpper();

    The toupper function isn't working though. How would I uppercase just the s in steinberg?

    OriginalGriffO L P 3 Replies Last reply
    0
    • D doughyi8u

      I'm trying to uppercase the second word in a string of two words (a first and last name).

      int index;
      string name = "Jeffrey steinberg";

      index = name.IndexOf(' ');
      name = name[index + 1].ToUpper();

      The toupper function isn't working though. How would I uppercase just the s in steinberg?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Here's the method I use:

      /// <summary>
      /// Convert the clipboard text to proper English capitalisation.
      /// If Control is down, use Title Case
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void butLowerCase_Click(object sender, EventArgs e)
      {
      bool sentenceCase = (ModifierKeys & Keys.Control) != Keys.Control;
      if (Clipboard.ContainsText())
      {
      string s = Clipboard.GetText();
      string[] lines = s.Split('\n');
      StringBuilder sb = new StringBuilder();
      string EOL = "";
      for (int i = 0; i < lines.Length; i++)
      {
      sb.Append(EOL);
      if (lines[i].Length > 1)
      {
      if (sentenceCase)
      {
      sb.Append(lines[i].Substring(0, 1).ToUpper());
      sb.Append(lines[i].Substring(1).ToLower());
      }
      else
      {
      // Title Case
      string[] words = lines[i].ToLower().Split(' ');
      string sep = "";
      foreach (string word in words)
      {
      if (word.Length > 0)
      {
      if (conjunctions.Contains(word))
      {
      sb.AppendFormat("{0}{1}", sep, word);
      }
      else
      {
      sb.AppendFormat("{0}{1}{2}", sep, word.Substring(0, 1).ToUpper(), word.Length > 1 ? word.Substring(1).ToLower() : "");
      }
      sep = " ";
      }
      }
      }
      }
      else
      {
      sb.Append(lines[i]);
      }
      EOL = "\n";
      }
      Clipboard.SetText(sb.ToString());
      }
      }

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      A 1 Reply Last reply
      0
      • D doughyi8u

        I'm trying to uppercase the second word in a string of two words (a first and last name).

        int index;
        string name = "Jeffrey steinberg";

        index = name.IndexOf(' ');
        name = name[index + 1].ToUpper();

        The toupper function isn't working though. How would I uppercase just the s in steinberg?

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

        Console.WriteLine( System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase( "Jeffrey steinberg" ) );

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Here's the method I use:

          /// <summary>
          /// Convert the clipboard text to proper English capitalisation.
          /// If Control is down, use Title Case
          /// </summary>
          /// <param name="sender"></param>
          /// <param name="e"></param>
          private void butLowerCase_Click(object sender, EventArgs e)
          {
          bool sentenceCase = (ModifierKeys & Keys.Control) != Keys.Control;
          if (Clipboard.ContainsText())
          {
          string s = Clipboard.GetText();
          string[] lines = s.Split('\n');
          StringBuilder sb = new StringBuilder();
          string EOL = "";
          for (int i = 0; i < lines.Length; i++)
          {
          sb.Append(EOL);
          if (lines[i].Length > 1)
          {
          if (sentenceCase)
          {
          sb.Append(lines[i].Substring(0, 1).ToUpper());
          sb.Append(lines[i].Substring(1).ToLower());
          }
          else
          {
          // Title Case
          string[] words = lines[i].ToLower().Split(' ');
          string sep = "";
          foreach (string word in words)
          {
          if (word.Length > 0)
          {
          if (conjunctions.Contains(word))
          {
          sb.AppendFormat("{0}{1}", sep, word);
          }
          else
          {
          sb.AppendFormat("{0}{1}{2}", sep, word.Substring(0, 1).ToUpper(), word.Length > 1 ? word.Substring(1).ToLower() : "");
          }
          sep = " ";
          }
          }
          }
          }
          else
          {
          sb.Append(lines[i]);
          }
          EOL = "\n";
          }
          Clipboard.SetText(sb.ToString());
          }
          }

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          A Offline
          A Offline
          Agent__007
          wrote on last edited by
          #4

          I also have something similar, except along with conjunctions, I skip articles and prepositions as well.

          You have just been Sharapova'd.

          1 Reply Last reply
          0
          • D doughyi8u

            I'm trying to uppercase the second word in a string of two words (a first and last name).

            int index;
            string name = "Jeffrey steinberg";

            index = name.IndexOf(' ');
            name = name[index + 1].ToUpper();

            The toupper function isn't working though. How would I uppercase just the s in steinberg?

            P Offline
            P Offline
            PANKAJMAURYA
            wrote on last edited by
            #5

            You can use the inbuilt library mathod ToTitleCase() as

            string name = "Jeffrey steinberg";
            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
            name = textInfo.ToTitleCase(name);

            For detail to use library method go to - https://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx[^]

            Pankaj Maurya Sr. Software Engineer Gurgaon, India

            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