splitting strings mac/windows

i have a problem with splitting strings. it seems that its different. text assets work the same but if i read textfiles i do not get the same result with this code:

fileNames : String[]=fileList.Split("\n"[0]);

this works just fine in windows standalone build but it does not mac build file is something like this:

line1 line2 line3

in mac i get one string like this: line1 line2 line3

so how to properly do this?

maybe its something with the text files

answers cross link: http://answers.unity3d.com/questions/220126/spliting-strings-macwindows.html

Mac and Windows use different characters for line endings (carriage returns), so you might want to check for “\r” as well.

Perhaps something like this (code not tested):

fileList = fileList.Replace("\r\n", "\n");
fileList = fileList.Replace("\r", "\n");
fileNames = fileList.Split("\n"[0]);

You could also do it in one line:

fileNames = fileList.Replace("\r\n", "\n").Replace("\r","\n").Split("\n"[0]);

Ordinarily you should be able to use Environment.NewLine, but there are issues with that apporach.

// NOTE: do not replace the "\r\n" with Environment.NewLine as it will break the code.
string[] fileNames = fileList.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);