How can I parse HTTP urls in C#?

前端 未结 3 1621
小蘑菇
小蘑菇 2020-12-01 16:50

My requirement is to parse Http Urls and call functions accordingly. In my current implementation, I am using nested if-else statement which i think is not an optimized way.

3条回答
  •  攒了一身酷
    2020-12-01 17:22

    I combined the split in Suncat2000's answer with string splitting to get at interesting features of the URL. I am passing in a full Uri including https: etc. from another page as the navigation argument e.Parameter:

    Uri playlistUri = (Uri)e.Parameter;
    string youtubePlaylistUnParsed = playlistUri.Query;
    char delimiterChar = '=';
    string[] sections = youtubePlaylistUnParsed.Split(delimiterChar);
    string YoutubePlaylist = sections[1];
    

    This gets me the playlist in the PLs__ etc. form for use in the Google APIs.

提交回复
热议问题