Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing a string to an array in C#

I have this string :

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

I just want the numbers to be stored in the array result[] like

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

Can anyone help me with this.

like image 774
Krishh Avatar asked Feb 03 '26 03:02

Krishh


1 Answers

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"
like image 155
Darin Dimitrov Avatar answered Feb 04 '26 20:02

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!