Convert Char to string in C # [duplicate]

3

I am trying to convert a char to string to use in split (), but it is not advancing

string path = HttpContext.Current.Request.Url.AbsolutePath;
path = path.ToString();
string[] caminho = path.Split("/");

I get the following error Argumento 1:Não é possivel converter string para char Do you have any way of doing this? this using C # mvc asp.net

    
asked by anonymous 27.11.2017 / 13:23

1 answer

4

You are using double quotation marks, which is the literal of string . This overload method of Split expects char . Use simple quotes like this:

string[] caminho = path.Split('/');

From documentation :

  

Char constants can be written as literals of   characters, hexadecimal escape sequence or as representation   Unicode. You can also convert the character codes   integrals. In the following example, four char variables are   initialized with the same character X:

char[] chars = new char[4];

chars[0] = 'X';        // Character literal
chars[1] = '\x0058';   // Hexadecimal
chars[2] = (char)88;   // Cast from integral type
chars[3] = '\u0058';   // Unicode

foreach (char c in chars)
{
    Console.Write(c + " ");
}
// Output: X X X X
    
27.11.2017 / 13:23