Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have previous code for textbox trim in VB is
VB
If Trim(textbox.Text) = "" Then
            Message.Text = "name is required"
            Exit Sub
        End If



I want to use it in C# then how can I use ?
Posted

Try this code:
C#
if (String.IsNullOrEmpty(String.Trim(textbox.Text)))
{
    Message.Text = "name is required";
    return;
}
 
Share this answer
 
All strings have a Trim method :
C#
string s = textbox1.Text.Trim();
 
Share this answer
 

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