-4

I have image tag in my html like img src="/images/image.jpg".

I want it like src="mydomain.com/images/image.jpg"

So I want to replace all src="/ to src="mydomain.com/. I tried this

                      string repto = "src=\"/" + strLink.HRef + "/";
                      strEncode.Replace("src=\"/", repto);

strEncode contains my html. I tried many ways but nothing is working. Please help, if any body has any idea about this. Thanks

3 Answers3

2

Maybe

html_string.Replace("src=\"/images", "src=\"mydomain.com/images");

?

MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
i486
  • 6,491
  • 4
  • 24
  • 41
  • 1
    "not working". Aha. For my own I upvoted this as being a correct way. – C4d Oct 01 '14 at 11:40
  • 1
    Replace "html_string" with the name of your variable. Why not working? – i486 Oct 01 '14 at 11:43
  • I already replaced it, But not working I think It is not getting Escape character there. – user3815579 Oct 01 '14 at 11:50
  • "I think" is not enough. After replacing, why arnt you just echoing the string out to check how it looks like? I dont think the poster is responsible for every written character. – C4d Oct 01 '14 at 11:55
2
string foo = @"src=\"/images/image.jpg\"";
string bar = foo.Replace("src=\"", "src=\"mydomain.com");
Gmnd-i
  • 124
  • 1
  • 1
  • 12
2

String#Replace does not change the value of strEncode, in fact it returns a new string with the encoded value. So this may help you out:

strEncode = strEncode.Replace("src=\"/", repto);
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111