Solved

Convert first letter in a string to capital

Posted on 2014-10-21
5
119 Views
Last Modified: 2014-10-21
I have a Text Box, (say txtBox1) which I am asking the user to enter some text in.
I need to check if the first letter in the box's text is uppercase.
If not uppercase convert ONLY the first letter to uppercase and keep the remaining letters as lowercase.

Thank you
0
Comment
Question by:adamtrask
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 40395461
There might be more efficient ways to do this, but this will give you the result your looking for.  In the Leave event for your text box drop in this line of code.

        private void textBox1_Leave(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text[0].ToString().ToUpper() + textBox1.Text.Substring(1);
        }

Open in new window

0
 

Author Comment

by:adamtrask
ID: 40395595
Thank you. This partly works as it changes the first letter to uppercase, but if the user enters an uppercase letter in the middle of the word like "adAm"? It would become AdAm!

Is there a way to convert the rest of the text to lowercase?

Thanks
0
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 40395639
Yeah, not a problem, you just need to add a .ToLower() to the second part like below.

textBox1.Text = textBox1.Text[0].ToString().ToUpper() + textBox1.Text.Substring(1).ToLower();

Open in new window

0
 

Author Closing Comment

by:adamtrask
ID: 40395693
Thank you so much.
0
 
LVL 9

Expert Comment

by:dustock
ID: 40395696
No problem, glad I could help.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question