Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want a code that make all first letters in every words in the sentence : capital and the rest of letters small. and i need them to be printed in listbox.
by using for example :
for
if
chars
toupper
and any other funiction that may help .


thans for help..
Posted

I have used this helper method for a while to do this:
C#
public static string ToTitleCaseString(object value)
{
   if (value == null || value.ToString().Length == 0) { return string.Empty; }
   string s = System.Convert.ToString(value, CultureInfo.InvariantCulture);
   return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(s.ToLower());
}
 
Share this answer
 
Comments
bbirajdar 13-Dec-12 9:57am    
+5.. Bookmarked
fjdiewornncalwe 13-Dec-12 10:30am    
Thanks.
__TR__ 14-Dec-12 13:36pm    
My 5!
Hi,
Ex)
string str="hello";

str=str.substring(0,1).toUpper()+str.substring(1).tolower();
 
Share this answer
 
Comments
fjdiewornncalwe 13-Dec-12 10:31am    
Will work if there is only 1 word in the argument, but what about if there are multiple words, ie. "my title". The result in your case would be "My title" instead of "My Title".
I got the answer
VB
    Dim s As String = "tariq naji ahmed";
    Dim a As String = 0
    For i As Byte = 0 To s.Length - 1
        If s.Chars(i) = s.Chars(0) Then

            a = s.ToUpper().Chars(i)

        ElseIf s.Chars(i) = " " Then
            a = a & s.Chars(i)
            i += 1
            a = a & s.ToUpper().Chars(i)

        Else
            a = a & s.Chars(i)
        End If
    Next
    TextBox1.Text = a

End Sub

[Edit]Code block added[/Edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900