Most optimal way to parse querystring within a string in C#

前端 未结 3 1687
迷失自我
迷失自我 2020-12-14 01:25

I have a querystring alike value set in a plain string. I started to split string to get value out but I started to wonder that I can proabably write this in one line instea

相关标签:
3条回答
  • 2020-12-14 01:55

    RichardOD is on it with HttpUtility.ParseQueryString but don't forget to look at TryParse.

    You can TryParse int, DateTimes etc

    How do you test your Request.QueryString[] variables?

    0 讨论(0)
  • 2020-12-14 02:00

    You can do it this way:

    using System.Collections.Specialized;
    
    NameValueCollection query = HttpUtility.ParseQueryString(queryString);
    Response.Write(query["id"]);
    

    Hope it helps.

    0 讨论(0)
  • 2020-12-14 02:04

    Look at HttpUtility.ParseQueryString. Don't reinvent the wheel.

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