hi
i want to do the capital letter of erver word in text box
what i use the function or code
i mean
i write in my text box i.e " dharmesh sharma "
now this string will me make like this "Dharmesh Sharma" in textbox
how do this in textbox
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilanka DharmadasaPosted Nov 19, 2009, 4:22 AM
Add these two lines with other using statements.
using System.Globalization;
using System.Threading;
Then write following code.
private void textBox1_Leave(object sender, EventArgs e)
{
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
textBox1.Text = textInfo.ToTitleCase(textBox1.Text);
}
This will change the text wehn you leave the text box. If this should be changed, then copy this code under the event you want.
If you need help on this, let me know.
If you find this useful, please mark this as accepted.
Muhammad Shahid FarooqPosted Nov 19, 2009, 4:58 AM
Use the following small snippet, this will help you
private void textBox1_Leave(object sender, System.EventArgs e)
{
textBox1.Text = ConvertToPascalCase(textBox1.Text).TrimStart();
}
public static string ConvertToPascalCase(string str)
{
//if nothing is proivided throw a null argument exception
if (str == null) throw new ArgumentNullException("str", "Null text cannot be converted!");
if (str.Length == 0) return str;
//split the provided string into an array of words
string[] words = str.Split(' ');
//loop through each word in the array
for (int i = 0; i < words.Length; i++)
{
//if the current word is greater than 1 character long
if (words[i].Length > 0)
{
//grab the current word
string word = words[i];
//convert the first letter in the word to uppercase
char firstLetter = char.ToUpper(word[0]);
//concantenate the uppercase letter to the rest of the word
words[i] = " " + firstLetter + word.Substring(1);
}
}
//return the converted text
return string.Join(string.Empty, words);
}
Lalit MPosted Nov 19, 2009, 4:56 AM
set the TextBox.CharacterCasing to Upper.
Gaurish KumarPosted Nov 19, 2009, 4:27 AM
Create one function like this