简体   繁体   中英

C# String.replace is not working

I have this string from which I want to remove the Hosting html part.

string r = @"2014-09-18 20:59:53|
<!-- Hosting24 Analytics Code -->
<script type=""text/javascript"" src=""http://stats.hosting24.com/count.php""></script>
<!-- End Of Analytics Code -->";

But

r = r.Replace(
@"<!-- Hosting24 Analytics Code -->
<script type=""text/javascript"" src=""http://stats.hosting24.com/count.php""></script>
<!-- End Of Analytics Code -->","");

Is not working. I get the same annoying original string.This has been driving me crazy

From examining your string, it appears you're trying to remove everything after the first bar character. If that's the case, this might work better:

r = r.Split('|')[0];

The code you've posted does remove the string as you are trying to. You can verify this yourself here.

https://dotnetfiddle.net/p4lchi

The string you are ultimately examining must come from some other source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM