The Trim function of Delphi

Source: Internet
Author: User

About three trim functions

Function prototype functions Trim(const s:string): string; The whitespace and control characters before and after the string are cleared out.

Functional prototype function Trimleft(const s:string): string; Clear whitespace and control characters to the left of the string.

Functional prototype function trimright(const s:string): string; Clear the whitespace and control characters to the right of the string.

Example of trim real-world application scenario

Here's a real-world scenario that uses the Trim function of Delphi, and reading it may give you a deeper understanding of the application of trim in real development

Delphi database application, want to do a user identification of the login window, is to enter the user name and password and then go to the database to verify the user identity, but the program runs, although every time the user name and password entered is correct, but the program always said my password input error, the problem is where? Please look at the code

If Ibt_user_pass. Recordcount=1 thenbegin    if Ibt_user_pass. Fieldbyname (' passwd '). Asstring=edit2. Text then    //****        form_student_login. Hide    Else        application. MessageBox (' Please confirm the password is correct! ', ' passwords do not match ', MB_OK);    Endelse    Application. MessageBox (' Please confirm that the user name is correct! ', ' Without this user ', MB_OK) end;

Only to know that it was added//**** comments that line of code there is a problem, the database if a field is a char type of data, the data will be stored automatically after the string to fill the grid to meet the needs of the number of bits , so on the surface, the obtained password and I entered the same password, is actually not the same.

Workaround:

  Option 1:

If Ibt_user_pass. Fieldbyname (' passwd '). asstring = Edit2. Text Then

Switch

Trim (Ibt_user_pass. Fieldbyname (' passwd '). Asstring=edit2. Text Then

Trim function is to remove the extra space in the string

  Option 2:

The char type of the database is changed to varchar type

The Trim function of Delphi

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.