Trim, TrimStart, and TrimEnd string processing functions in. net (1/2)

Source: Internet
Author: User

. Net provides three string processing functions for us. I believe you have used them all over: trim, trimstart, and trimend.

However, in practical applications, trim one by one is quite troublesome. For analysis, see the following controller and Its model:

Public class personcontroller: controller
{
Public actionresult query (string name)
{
//...
}
//...
[Httppost]
Public actionresult create (person)
{
//...
}
[Httppost]
Public actionresult create2 (formcollection collection)
{
Person = new person ();
Updatemodel (person, collection );
//...
}
//...
}

Public class person
{
Public int id {get; set ;}
Public string name {get; set ;}

} There are roughly three trim types:

The string parameter in the action, such as the name parameter in the query method.
The string attribute of complex type parameters in action, such as the name attribute of person in the create method.
Explicitly bound string attributes of complex types in action, such as the name attribute of person in the create2 method.

If the model is more complex:

Public class person
{
Public int id {get; set ;}
Public string name {get; set ;}
Public string [] hobbies {get; set ;}
Public person father {get; set ;}

} 1 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.