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

后端 未结 7 1562
野的像风
野的像风 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 03:45

    I found this link immediately on a google search.

    C# - indexOf the nth occurrence of a string?

    Get the IndexOf the first occurrence of the string.

    Use the returned IndexOf's startIndex +1 for the starting position of the second IndexOf.

    Substring it into two strings at the appropriate index of the "1" character.

    Concat it back together with the "2" character.

提交回复
热议问题