0

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

4
  • 5
    I believe you are trying to extract Date from your string, why not do string date = r.Split('|').First(); Commented Sep 18, 2014 at 17:01
  • 3
    Compare the strings at runtime. Hint: whitespace. Commented Sep 18, 2014 at 17:02
  • 2
    Note that, for multiline @ strings like this to work the way you want them to, they can't be indented. See ideone.com/ffyQuA Commented Sep 18, 2014 at 17:03
  • And what result do you expect? Commented Sep 18, 2014 at 17:05

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

Comments

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.

6 Comments

Your fiddle happens to work because you indented both @ strings in exactly the same way.
@RobertHarvey: Yes, that is a necessary condition. The shown code also has that property.
shouldn't that be a comment. I mean your answer could be "your current code works fine, the problem is elsewhere"
@recursive: If the posted code really had that property, it would have worked already.
@EmpereurAiman: You used the @ symbol, which means "This is exactly how I want this multiline string to look, indentation and all."
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.