Path.Combine for URLs?

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Path.Combine for URLs?

Message par Clippy »

Path.Combine for URLs?
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Path.Combine for URLs?

Message par Clippy »

There [is a Todd Menier's comment above](https://stackoverflow.com/questions/372865/path-combine-for-urls/43582421#comment33212350_372865) that [Flurl](https://flurl.dev/) includes a `Url.Combine`.

More details:

Url.Combine is basically a Path.Combine for URLs, ensuring one
and only one separator character between parts:

```
var url = Url.Combine(
"http://MyUrl.com/",
"/too/", "/many/", "/slashes/",
"too", "few?",
"x=1", "y=2"
// result: "http://www.MyUrl.com/too/many/slashes/too/few?x=1&y=2"

```

Get [Flurl.Http on NuGet](https://www.nuget.org/packages/Flurl.Http/):

PM> Install-Package Flurl.Http

Or [get the stand-alone URL builder](https://www.nuget.org/packages/Flurl/) without the HTTP features:

PM> Install-Package Flurl
Répondre

Revenir à « .NET & C# »