How to separate a string in unity c #

1

I would like to know how to separate a string in C # unity, I ended up looking at some similar questions for C # and not on unity, I often found this example

string[] linha = reader.ReadLine().Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

and the error that the StringSplitOptions function does not exist in context, then I would like to know a method.

Here's what I want to do, I'll have in a TXT file a line of text that I want to separate by the text for each || , Ex:

" Você acorda, o que faz?||Dormir mais||2||Levantar||1||Sentar e esperar||2||Cair da cama||3$2||1<> "

I want to separate this text as follows;

string lin1 = "Você acorda, o que faz?"
string lin2 = "Dormir mais"
string lin3 = "2"
string lin4 = "Levantar"
string lin5 = "1"
string lin6 = "Sentar e esperar"
string lin7 = "2"
string lin8 = "Cair da cama"
string lin9 = "3$2"
string lin10 = "1"

Note: < > in theory is to serve as line break;

    
asked by anonymous 09.11.2017 / 18:33

1 answer

1

What happens is that Unity runs on a very old version of Mono. And in this release, some things we're used to are not implemented.

The Split method, in this version, has no overhead that accepts an array as a parameter and a StringSplitOptions .

In contrast, there is an overhead that accepts an array of chars and a StringSplitOptions .

In this case, it will be impossible to break the text to each pair of pipes ( | ), but since you will be using the RemoveEmptyEntries option, / p>

reader.ReadLine().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

See working in .NET Fiddle.

    
09.11.2017 / 18:40