This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23750|Reply: 3

[Source] .net Read & Split Parameters How to find the parameters you want

[Copy link]
Posted on 11/6/2015 5:36:23 PM | | |
For example, there is a string: aaa=1&ccc=test&ddd=code123&..... and many other parameters!

If it is an address bar parameter, you can get the value by simply Request.QueryString["parameter name"] or directly Request["parameter name"]

If it's just a string and you want to parse it, there are two ways
1 Regular Expression 2Split and then perform split traversal
Regular expression method:

  1. /// <summary>
  2.         /// 获取url参数
  3.         /// </summary>
  4.         /// <param name="paramName">参数名称</param>
  5.         /// <param name="paramsStr">整个url</param>
  6.         /// <returns></returns>
  7.         public static string GetParams(string paramName, string paramsStr)
  8.         {
  9.             Regex regParam = new Regex("(?:^|&)" + paramName + "=(?<Value>[^&]*)", RegexOptions.IgnoreCase);
  10.             Match mth = regParam.Match(paramsStr.Trim());
  11.             if (mth.Success)
  12.             {
  13.                 //匹配成功
  14.                 return mth.Groups["Value"].Value;
  15.             }
  16.             else
  17.             {
  18.                 return null;
  19.             }
  20.         }
Copy code


As for the second method, you have to split('&') first, and then iterate through this array, and then split('=') to determine whether the [0] parameter name is equal to the specified value, and if it is a specified value, then directly return to the [1] double for loop





Previous:bootstrap-table server paging background value problem
Next:bootstrap glyphicons-halflings-regular.woff2 file reports a 404 error
Posted on 11/9/2015 9:35:18 AM |
benefited
 Landlord| Posted on 2/26/2017 3:26:22 PM |
.net/c# to get the parameter value of the URL
http://www.itsvse.com/thread-3521-1-1.html
(Source: Architect)
 Landlord| Posted on 4/9/2023 2:13:56 PM |
How to split a string in C# "----" with four-division
The following two are fine. In fact, there is a truth. Because it went to the sky
Split(new string[] { "----" }, StringSplitOptions.RemoveEmptyEntries);
Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com