>using System; > >class Program >{ > static void Main(string[] args) > { > string myString = "{fname='Joe', lname='Smith'}"; > > Person SomePerson = new Person(myString); > > Console.WriteLine(SomePerson.FirstName); > Console.WriteLine(SomePerson.LastName); > Console.WriteLine("Press any key"); > Console.ReadKey(); > } >} > >public class Person >{ > public string LastName { get; set; } > public string FirstName { get; set; } > public Person(string tString) > { > // Remove the {}' characters so that the string looks > // like "fname=Joe, lname=Smith" > tString = ((tString.Replace("{", "")).Replace("}", "")).Replace("'", ""); > > FirstName = MyMethods.ParseString("fname", tString, ','); > LastName = MyMethods.ParseString("lname", tString, ','); > } >} >public class MyMethods >{ > public static string ParseString(string ParamName, string StringToParse, char Delimiter) > { > string[] NameValues; > string[] KeyValues = StringToParse.Trim().Split(Delimiter); > > foreach (string oString in KeyValues) > { > NameValues = oString.Trim().Split('='); > > if (NameValues[0] == ParamName) > return NameValues[1]; > } > return ""; > } >} > >Hi,
>>string myString = "{fname='Joe', lname='Smith'}"; >>>>
>>var myObject = new {fname='Joe', lname='Smith'};
>>
>>>>var myObject = new (myString);
>>
>>