views:

520

answers:

1

In Silverlight 2, using C# on ASP.NET, you can pass a set of Initialization Parameters by assigning the Silverlight object's InitiParams with a string that's a series of comma separated key/value pairs.

I've seen other systems that have a similar mechanism for passing around collections of key/value pairs as a single string.

What is the solution for specifying a value that has a comma in it?

For example this string doesn't have a problem:

string s1 = "key1=value1,key2=value2";

but this one does:

string s2 = "key1=value1,key2=two,values";

i.e. the "two,values" needs to have the comma escaped in some way...

+2  A: 

Unfortunately, after a quick Googling I don't think the parsing mechanism for InitParams follows any sort of encoding scheme. It'd actually be better if it were a URL Query String fragment, which has a fairly standard encoding and rules and is comma friendly.

So I think your only option is to use a different delimeter, such as the pipe symbol |.

E.g.:

key1=value1,key2=two|values

If that had to be a comma in the value for whatever reason, you could always do String.Replace...

Randolpho