2

I have a string, with data as shown below. How I read separately each property values.

ie PCIaaS_CardId=value; BillingFirstName=value;

PCIaaS_CardId=value&BillingFirstName=value&BillingLastName=value&BillingCompanyNamevalues=&BillingAddress1=value&BillingAddress2=values&BillingCity=value

1
  • It's not clear what you are asking. I assume the second line is an example of a string to be parsed? Is this a querystring from a URL, or does it just happen to have same/similar format? Commented Mar 6, 2014 at 10:30

4 Answers 4

10

That looks like a HTTP query string, for which you can use HttpUtility.ParseQueryString.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks CompuChip... :). You give a great thread. I found a similar question in stackoverflow.com/questions/11956948/…
1
var propertyParts = yourString.Split('&');
foreach (var propertyStr in propertyParts)
{
    var keyValue = propertyParts.Split('=');
}

Comments

0

You can convert string to dictionary:

Dictionary<string, string> values = 
    str.Split('&').Select(s => s.Split('=')).ToDictionary(a => a[0], a => a[1]);

Then getting value by key will look like:

string firstName = values["FirstName"];

Comments

0

string[] abc = "value&BillingFirstName=value&BillingLastName=value&BillingCompanyNamevalues=&BillingAddress1=value&BillingAddress2=values&BillingCity=value".Split(new char[] { '&' });

Then you can access it by abc[index]

OR

string[] abc = yourString.Split(new char[] { '&' });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.