The replace function in JavaScript and the replace method in C #

Source: Internet
Author: User

This is a problem that has never been noticed. The point is that replace in C # is a global replacement character (string), while in Javascript, it is only replaced with the first matched character.Code, JavaScript is as follows:

 
VaRSource='Abc123abc456abc';
VaRDesc=Source. Replace ('ABC','');
Alert (DESC );

The result is 123abc456abc.

The code in C # is as follows:

String source = "abc123abc456abc"; string DESC = source. Replace ("ABC", ""); console. Write (DESC );

Result: 123456

The corresponding JavaScript function should be written as follows:

 
VaRSource='Abc123abc456abc';
VaRDesc=Source. Replace (/ABC/G,'');

In this case, the implementation of C # is hard to understand. So we decompiled the string.

It seems that this should introduce the. NET kernel function. Then use msil to decompile mscorlib. dll and find the replace implementation:

We can see that it is internally called the pencil class library. Of course, this class library has been encapsulated internally and we cannot know the implementation.

Here we leave a todo.

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.