- Home /
String.Split With Backslash
var lines = fileContents.Split("n"[0]);
works but I want to do this
var lines = fileContents.Split("\"[0]);
but it does not allow me to use a backslash? I need to parse file locations. Any Ideas?
Don't understand the use of [0]
! If you need char
ins$$anonymous$$d of string
, just use the correct syntax:
"n"; // this is a string of length 1
'n'; // this is a char
No, [0]
is how you do chars in Unityscript. Single quotes won't work, since those are for strings. (You can use that to have double quotes in strings without having to escape them.)
Oh yes sorry. I didn't realize it was in UnityScript. Good to know.
Answer by Eric5h5 · Jul 03, 2012 at 06:05 PM
You don't need to use a backslash at all, just use /
for path separators. Actually this is mandatory unless you're 100% sure you're never going to use your app on anything except Windows, but even in that case it's a good idea to get in the habit of using /
because that's universal and works everywhere (including Windows).
In those cases where you do need to use a backslash for whatever reason, the \` character is an escape character, so to use the actual
\ character you should use
\`.
Answer by Kryptos · Jul 03, 2012 at 07:21 PM
To parse file location, just use the C# built-in Path class. It is supported on any platform with the exception of a few methods when building the game as a webplayer.
edit: As @Eric5h5 cleared up, the Path class is available for the whole .Net framework, not just C#.
That's not the C# Path class, it's the .NET Path class. (Just to avoid confusion with people thinking it only works in C#.)
Yes. Once again I forgot that not everybody uses C# with Unity. Thanks @Eric5h5 for clearing that up.
Your answer
Follow this Question
Related Questions
What do you say the best way to store a string be? 2 Answers
Split string from PlayePrefs 1 Answer
How to convert a string to int array in Unity C# 1 Answer
String split script 1 Answer