Unique String Format

Last post 04-12-2009 3:55 AM by TATWORTH. 2 replies.

Sort Posts:

  • Unique String Format

    04-09-2009, 7:14 AM
    • Member
      11 point Member
    • Blue_Wolf101
    • Member since 01-03-2008, 2:26 PM
    • Posts 48

    I have a login system that prints out the name of the user on the form in a label.

     The usernames follow this standard, using my username as an example: BWolf, so the first 2 characters are in upper case and just the 1st initial is used from the forename.

    Sometimes users login in all lower case and this still reflects on the form.

     Is there a way I can convert the label to show our 'correct' format?

  • Re: Unique String Format

    04-09-2009, 8:12 AM
    Answer
    • Star
      10,552 point Star
    • getchinna_sv
    • Member since 09-10-2008, 8:29 PM
    • Hyderabad
    • Posts 1,807

    use ToLower(); ToUpper(); methods of string....

    Chinna_sv...
  • Re: Unique String Format

    04-12-2009, 3:55 AM
    Answer
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     The following unit test illustrates how to set your casing:

        #region " SetUserCasing       "
        /// <summary>
        /// Test setting case on user name.
        /// </summary>
        /// <remarks>
        /// This was in answer to http://forums.asp.net/t/1408495.aspx
        /// </remarks>
        [Test]
        public void SetUserCasing()
        {
          var input = "bwolf";
          string output;
          //// Start of what would normally be SetUserCasing(string output)
          if (string.IsNullOrEmpty(input))
          {
            throw new ArgumentException("input may not be null of empty");
          }
          if (input.Length > 2)
          {
            output = input.Substring(0, 2).ToUpperInvariant() + input.Substring(2).ToLowerInvariant(); 
          }
          else
          {
            output = input.ToUpperInvariant();
          }
          //// Normally return(output); at this point
          Assert.AreEqual("BWolf", output);
        }
        #endregion

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
Page 1 of 1 (3 items)