资本和小写字母 [英] capital and small letters

查看:64
本文介绍了资本和小写字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个代码,它会在句子中的每个单词中生成所有首字母:大写,其余字母小。我需要将它们打印在列表框中。

使用例如:

for

if

chars

toupper

和任何其他可能有用的小说。





thans求助.. ..

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..

推荐答案

我已经使用了这个辅助方法一段时间来做到这一点:

I have used this helper method for a while to do this:
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());
}




ex)

string str =hello;



str = str.substring(0,1).toUpper()+ str.substring(1).tolower();
Hi,
Ex)
string str="hello";

str=str.substring(0,1).toUpper()+str.substring(1).tolower();


我得到了答案

I got the answer
    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]


这篇关于资本和小写字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆