目标:在用户输入姓名时解析姓名,并显示带有第一个中间名和姓氏的消息框。现在它只在你输入三个名字时才有效,如果你尝试两个它会崩溃,我确定这是我的数组的原因,但我不确定我错在哪里。超级新手,我自己学习,所以任何帮助将不胜感激!!
用户看到的 PS GUI 只是一个输入块,供他们将他们的名字输入一行,每个单词之间有间距。
private void btnParseName_Click(object sender, System.EventArgs e)
{
string fullName = txtFullName.Text;
fullName = fullName.Trim();
string[] names = fullName.Split(' ');
string firstName = "";
string firstLetter = "";
string otherFirstLetters = "";
if (names[0].Length > 0)
{
firstName = names[0];
firstLetter = firstName.Substring(0, 1).ToUpper();
otherFirstLetters = firstName.Substring(1).ToLower();
}
string secondName = "";
string secondFirstLetter = "";
string secondOtherLetters = "";
if (names[1].Length > 0)
{
secondName = names[1];
secondFirstLetter = secondName.Substring(0, 1).ToUpper();
secondOtherLetters = secondName.Substring(0).ToLower();
} …Run Code Online (Sandbox Code Playgroud) 我在这做错了什么?我希望用户名在输出中显示为正确但我无法弄明白.
string proper = this.xTripNameTextBox.Text;
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(proper);
this.xTripOutputLabel.Text = proper + Environment.NewLine + "The total gallons you would use: " + Output.ToString("0") + Environment.NewLine + "Total amount it will cost you: " + Coutput.ToString("C") + Environment.NewLine +" Your customer number is " + rnd1.Next(1, 1000).ToString();
Run Code Online (Sandbox Code Playgroud) 我怎么能把每个字的每个第一个字母大写?我是新手,所以这将是一个很大的帮助.
像大卫保罗这样的大卫保罗