How do I replace a specific occurrence of a string in a string?

后端 未结 7 1527
野的像风
野的像风 2020-12-18 03:12

I have a string which may contain \"title1\" twice in it.

e.g.

server/api/shows?title1=its always sunny in philadelphia&title1=breaking ba

相关标签:
7条回答
  • 2020-12-18 04:04

    The way P.S.W.G did is really awesome. but below I mentioned one simple way to get it done for those who do have problem in lambda and regex expression..;)

    int index = input.LastIndexOf("title1=");

    string output4 = input.Substring(0, index - 1) + "&title2" + input.Substring(index + "title1".Length, input.Length - index - "title1".Length);

    0 讨论(0)
提交回复
热议问题