Tags

, , ,

Hey,

Recently I had a requirement where I was suppose to hit a webpage along with some values passing as parameters in QueryString.

In few parameters the values were dynamics so I used Comma to separate the Values in the same string. But in order to capture those values separately I had to split the string on Commas basis.

This is made possible with help of Split method. Split separates strings with delimiters.

Eg:

String Sentence = "My name is Ashwani";
String[] Words = Sentence.Split(' ');

Output:


Words[0]=My
Words[1]=Name
Words[2]=is
Words[3]=Ashwani

In my case I used it with a comma delimiter as:

String[] Hobbies = Request.QueryString["Hobbies"].Split(',');

This separated all the hobbies of a person in different index of an Array(String);

Kindly visit my next post for the Opposite i.e.  Joining the Strings using Delimiter.

 
Thanks !!!
🙂

Advertisements