Split in single quotes'

2

I have a string where there are single quotes (') and would like to split but by setting, '''); , it breaks the code.

splitString = splitLines[i].Split(' ', ',', ';', '"', '(', ')', '!', '?', ':', '…', '„', '“', '¿', '¡');
    
asked by anonymous 05.03.2018 / 16:14

1 answer

8

As it stands you will generate a syntax error.

You can give a scape \' :

string[] resultado = x.Split(new char[] { '\'' }, StringSplitOptions.None);
Console.WriteLine(String.Format("Resultado: {0},{1}", resultado[0], resultado[1]));

Or instead of passing a char array as a parameter you can use string:

string[] resultado2 = x.Split(new string[] { "'" }, StringSplitOptions.None);
Console.WriteLine(String.Format("Resultado2: {0},{1}", resultado2[0], resultado2[1]));

Example Online: .Net Fiddle

Method Split

    
05.03.2018 / 16:40