Split in single quotes '

Asked

Viewed 793 times

3

I have a string where there are simple quotes (') and would like to make a split but by putting, ''');, he breaks the code.

splitString = splitLines[i].Split(' ', ',', ';', '"', '(', ')', '!', '?', ':', '…', '„', '“', '¿', '¡');
  • I don’t know much about C# but it’s not just escaping (')?

1 answer

10


The way it is you will generate a syntax error.

You can take 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]));

Online Example: .Net Fiddle

Method Split

Browser other questions tagged

You are not signed in. Login or sign up in order to post.