-4

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.

4

5 回答 5

2

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();
于 2012-07-26T12:44:36.437 回答
2

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
于 2012-07-26T12:46:31.930 回答
0

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[] {'&'});
于 2012-07-26T12:42:11.663 回答
0

maybe you want to convert to char[] array instead string[] array. to do this use char[] arr = obj.QueryString.ToCharArray()

于 2012-07-26T12:43:29.153 回答
0

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()
于 2012-07-26T12:46:59.700 回答