I have a object of type string,I want to convert it to String array
here the code is
obj.QueryString =HttpContext.Current.Request.Url.PathAndQuery;
string[] arr =obj.QueryString;
QueryString is of type string.
I have a object of type string,I want to convert it to String array
here the code is
obj.QueryString =HttpContext.Current.Request.Url.PathAndQuery;
string[] arr =obj.QueryString;
QueryString is of type string.
a string is nothing more then an array of chars, so if you want to split up the strings letters into a different string array seperatly you could do something like this:
string myString = "myString";
string[] myArray = new string[myString.Length];
for(int i = 0; i < myString.Length; i++)
{
myArray[i] = myString[i].ToString();
}
or Char Array:
string theString = "myString";
char[] theStringAsArray = theString.ToCharArray();
You can directly access the each index within the string. For example
string value = "Dot Net Perls";
char first = value[0];
char second = value[1];
char last = value[value.Length - 1];
// Write chars.
Console.WriteLine("--- 'Dot Net Perls' ---");
Console.Write("First char: ");
Console.WriteLine(first);
Console.Write("Second char: ");
Console.WriteLine(second);
Console.Write("Last char: ");
Console.WriteLine(last);
Output
--- 'Dot Net Perls' ---
First char: D
Second char: o
Last char: s
Insert whatever character you want to split on instead of the "&" argument in the Split method call.
obj.QueryString =HttpContext.Current.Request.Url.PathAndQuery;
string[] arr =obj.QueryString.Split(new char[] {'&'});
maybe you want to convert to char[] array instead string[] array. to do this use char[] arr = obj.QueryString.ToCharArray()
Here, this will make an array that may or may not fit your criteria.
var myArray = (from x in obj.QueryString select x.ToString()).ToArray()