Davy Quyo
Davy Quyo

Reputation: 102

Best way to convert a specific string to array

I made a control

and I generated a string with javascript from a javascript array using

Sys.Serialization.JavaScriptSerializer.serialize(array);

this is the string generated

"["name", "Code", "Alias"]"

this string is send to my control with a postback.

Now I need to know the best way to make an array from this string using C#

Upvotes: 1

Views: 63

Answers (2)

Selman Genç
Selman Genç

Reputation: 101681

You can use JavaScriptSerializer class:

var serializer = new JavaScriptSerializer();
var array = serializer.Deserialize<string[]>(yourString);

Note: You need to add a reference to System.Web.Extensions.dll

Upvotes: 3

Andrew Grinder
Andrew Grinder

Reputation: 595

String[] splitByComma = yourString.Split(',');
foreach(String splitString in splitByComma)
{
    splitString.Replace("\"","").Replace("[","").Replace("]","");
}

Upvotes: 0

Related Questions