CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.getting_started Tags:
Item Type: Date Entered: 7/12/2008 5:19:57 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 5 Views: 8 Favorited: 0 Favorite
6 Items, 1 Pages 1 |< << Go >> >|
"quilling123" <
NewsGroup User
Testing for upper case in a text box7/12/2008 5:19:57 PM

0

Hi,

 Say I have a text box t1, and t1.Text = "this Is an Example".  How do I search through this string and convert only the first letter of each word to uppercase?  The resulting string should look like t1.Text="This Is An Example"

I am using C#

Your help is greatly appreciated!

~Mark

"mbanavige" <>
NewsGroup User
Re: Testing for upper case in a text box7/12/2008 6:02:34 PM

0

A sample for converting a string to TitleCase can be found here: http://support.microsoft.com/kb/312890


Mike Banavige
~~~~~~~~~~~~
Dont 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.
"Jeev" <>
NewsGroup User
Re: Testing for upper case in a text box7/12/2008 6:17:58 PM

0

 

1         private string UpperCaseSentence(string sRawInput)
2            {
3                if (string.IsNullOrEmpty(sRawInput))
4                {
5                    return string.Empty;
6                }
7                string[] sArrayInput = sRawInput.Split();
8                StringBuilder sBuilder = new StringBuilder();
9                for (int i = 0; i < sArrayInput.Length; i++)
10               {
11                   sBuilder.Append(UppercaseFirstLetter(sArrayInput[i]));
12                   sBuilder.Append(" ");
13               }
14               return sBuilder.ToString().TrimEnd();
15           }
16           public string UppercaseFirstLetter(string Input)
17           {
18               if (string.IsNullOrEmpty(Input))
19               {
20                   return string.Empty;
21               }
22               char[] stringChars = Input.ToCharArray();
23               stringChars[0] = char.ToUpper(stringChars[0]);
24               return new string(stringChars);
25           }
 
Jeev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you get the answer to your question, please mark it as the answer.
"sahil31_mohali
NewsGroup User
Re: Testing for upper case in a text box7/12/2008 6:35:49 PM

0

Wink

jeev Your Code is fine.


sahil
"TATWORTH" <>
NewsGroup User
Re: Testing for upper case in a text box7/12/2008 6:55:40 PM

0

Try

    /// <summary>
    /// Lower case characters
    /// </summary>
    private const string FILTER_LOWER = "abcdefghijklmnopqrstuvwxyz";
    /// <summary>
    /// Upper Case Characters
    /// </summary>
    private const string FILTER_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    /// <summary>
    /// Alpha (upper and lower) characters
    /// </summary>
    private const string FILTER_ALPHA = FILTER_LOWER + FILTER_UPPER;

    #region " Init... "
    /// <summary>
    /// Capitalise initial letters
    /// </summary>
    /// <param name="input">The input string</param>
    /// <returns>String with start of words capitalised</returns>
    public static string InitCaps(string input)
    {
      input = "" + input;
      StringBuilder output = new StringBuilder(input.Length);
      bool start = true;
      for (int i = 0; i < input.Length; i++)
      {
        string letter = input.Substring(i, 1);
        if (start && FILTER_ALPHA.Contains(letter))
        {
          output.Append(letter.ToUpper());
          start = false;
        }
        else
          output.Append(letter);
        if (letter == " ") start = true;
      }
      return output.ToString();
    }
    #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.
"TATWORTH" <>
NewsGroup User
Re: Testing for upper case in a text box7/12/2008 6:58:08 PM

0

 The unit tests I used were:

    /// <summary>
    /// Test InitCaps
    /// </summary>
    [Test]
    public void TestInitCaps()
    {
      this.TestInitCapsTest("", "", true);
      this.TestInitCapsTest(null, "", true);
      this.TestInitCapsTest("A123", "A123", true);
      this.TestInitCapsTest("a123", "A123", true);
      this.TestInitCapsTest("hello world", "Hello World", true);
    }

    #region " TestInitCapsTest           "
    /// <summary>
    /// Test FilterUserName
    /// </summary>
    /// <param name="sIn">Input string</param>
    /// <param name="sExpect">Expected output</param>
    /// <param name="bExpect">Expected Test result</param>
    private void TestInitCapsTest(string sIn, string sExpect, bool bExpect)
    {
      string sOutput = CommonData.InitCaps(sIn);
      if (sExpect != sOutput)
      {
        Console.WriteLine("sOutput:" + sOutput);
        Console.WriteLine("sExpect:" + sExpect);
      }
      Assert.AreEqual(sExpect, sOutput);
    }
    #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.
6 Items, 1 Pages 1 |< << Go >> >|


Free Download:













quick database/checklist question

help please! "failed to map the path " error.

starting netscape as browser for web application

putting text files into a dataset

text box values are not being considered?

help in making a calculator

relative path without filename

date

run program??

'base' is ambiguous in the namespace 'spark.webapp'.

text file size limitation?

auto save ??

script in script

getting iis to render asp.net page

uning response.redirect to open in new window

printing

sql update issue

dns lookup

getting own page name

data insert then redirect

need help

simulate get programmatically (like a redirect, but with header info)

css layout problem on asp.net

can't get application to run after xcopy

cs0117: 'asp.webform1_aspx' does not contain a definition for 'fieldcheck'

better way of doing this? - quiz program answers

vacation schedule

system.web.httpcompileexception

dropdownlist issues

about difference in execution between windows forms, and web forms?

how to open a new pop up page with defined size and also passing an id to that page

random unique datarows.

the xml page cannot be displayed

getting currently logged in users id

uploading photo and inserting file name into database

positioning of user control problem

declaring a variable field

301 redirect problem...

visual web developer software

<authentication>-tag in web.config of a subfolder

when text includes an apostrophe

conditionall turning a requiredfieldvalidator on and off

gridview does not refresh in ie but does in firefox

opening a web site from asp application

how to access website on a local network?

debugging c# in visual studio

how to make multi language website

how to send mail with asp.net v1.1?????

weird javascript code getting added to page?

getting last day of this month

   
  Privacy | Contact Us
All Times Are GMT