How to replace url-parameter?

后端 未结 8 811
谎友^
谎友^ 2021-01-12 01:27

given is an URL like http://localhost:1973/Services.aspx?idProject=10&idService=14.

What is the most straightforward way to replace both url-paramet

8条回答
  •  轮回少年
    2021-01-12 01:40

    The most robust way would be to use the Uri class to parse the string, change te param values and then build the result.

    There are many nuances to how URLs work and while you could try to roll your own regex to do this it could quickly get complicate handling all the cases.

    All the other methods would have issues with substring matches etc and I don't even see how Linq applies here.

提交回复
热议问题