Test results of string Truncation in various browsers

Source: Internet
Author: User

In JavaScript how to intercept strings, I only listed these methods. I tested them in three mainstream modern browsers. The results are shown in the following table:

Browser Method Test result 1 Test result 2
IE 8 Regular 1 469 468
  Regular 2 422 438
  Slice 94 94
  Substring 125 140
Chrome 4.0.295 Regular 1 44 43
  Regular 2 37 37
  Slice 11 12
  Substring 10 11
FF 1, 3.6 Regular 1 144 142
  Regular 2 122 126
  Slice 10 9
  Substring 12 11

Note: Regular 1 is match (/. * (. {2})/) [1], regular 2 is match (/. {2} $ /).

The test code refers to "Efficiency of String concatenation" and "test comparison of three JSON methods". From the simple test results, we can see that, slice () is recommended for string truncation ().

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.