加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在C#中将字符串解析为数组

发布时间:2020-12-16 00:00:40 所属栏目:百科 来源:网络整理
导读:我有这个字符串: string resultString="section[]=100section[]=200section[]=300section[]=400"; 我只想将数字存储在数组结果[]中 result[0]=100result[1]=200result[3]=300result[4]=400 谁能帮我这个. 解决方法 NameValueCollection values = HttpUtilit
我有这个字符串:

string resultString="section[]=100&section[]=200&section[]=300&section[]=400";

我只想将数字存储在数组结果[]中

result[0]=100
result[1]=200
result[3]=300
result[4]=400

谁能帮我这个.

解决方法

NameValueCollection values = HttpUtility.ParseQueryString("section[]=100&section[]=200&section[]=300&section[]=400");
string[] result = values["section[]"].Split(',');
// at this stage 
// result[0] = "100"
// result[1] = "200"
// result[2] = "300"
// result[3] = "400"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读