How does QT remove spaces in strings?

Source: Internet
Author: User

Here we will introduce the two functions in QString.

1. QString: simplified () const

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

 

Returns a string to remove the spaces from the beginning to the end. Replace the spaces in each sequence with a space (the first and last spaces are removed)


For example: [cpp]
<SPAN style = "FONT-SIZE: 18px"> QString str = "lots \ t of \ nwhitespace \ r \ n ";
Str = str. simplified ();
// Str = "lots of whitespace"; </SPAN>

QString str = "lots \ t of \ nwhitespace \ r \ n ";
Str = str. simplified ();
// Str = "lots of whitespace"; '\ t',' \ n', '\ V',' \ F', '\ R ', ''all belong to the blank processing range.

 

2. QString: trimmed () const

Returns a string that has whitespace removed from the start and the end.

Returns a string that removes spaces from the beginning to the end. Also remove the leading and trailing Spaces

For example:


[Cpp]
<SPAN style = "FONT-SIZE: 18px"> QString str = "lots \ t of \ nwhitespace \ r \ n ";
Str = str. trimmed ();
// Str = "lots \ t of \ nwhitespace" </SPAN>

QString str = "lots \ t of \ nwhitespace \ r \ n ";
Str = str. trimmed ();
// Str = "lots \ t of \ nwhitespace"

 

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.