2011-03-23 48 views
-3

如何在文本框中输入查询值,第一个字母使用C#文本框中

+5

WebForms?的WinForms? WPF? MVC? – Oded 2011-03-23 11:06:23

+1

您是否需要在用户正在输入内容或进行某种提交事件时进行检查? – chillysapien 2011-03-23 11:06:44

+4

这是一个非常微不足道的问题。你应该花更多时间在C#教程上。 – 2011-03-23 11:09:03

回答

3
if(myTextBox.Text.StartsWith("B")) .... 
0

连接TextChanged事件,并检查第一个字母有B中的第一个字母。

0

您可以使用字符串StartsWith()方法。

if("Bar".StartsWith("B")) // .... 
if(Textbox.Text.StartsWith("B")) // .... 
1

我会觉得这是最有效的

if (myTextBox.Text.Length > 0 && myTextBox.Text[0] == 'B') 
0

你只是去到文本框的属性后,在你看到文本他们你只是给那里CHAR你想看什么。

1
static string UppercaseFirst(string UpperCase) 
{ 
    if (string.IsNullOrEmpty(UpperCase)) 
    { 
     return string.Empty; 
    } 

    return char.ToUpper(UpperCase[0]) + UpperCase.Substring(1); 
}