Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sherlockturtle · Jul 03, 2012 at 03:44 PM · stringfilessplitfoldersstring.split

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Jul 03, 2012 at 07:20 PM 0
Share

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
avatar image Eric5h5 · Jul 03, 2012 at 11:32 PM 0
Share

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.)

avatar image Kryptos · Jul 04, 2012 at 07:38 AM 0
Share

Oh yes sorry. I didn't realize it was in UnityScript. Good to know.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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 \`.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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#.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Jul 03, 2012 at 11:35 PM 0
Share

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#.)

avatar image Kryptos · Jul 04, 2012 at 07:39 AM 0
Share

Yes. Once again I forgot that not everybody uses C# with Unity. Thanks @Eric5h5 for clearing that up.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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

How to split a string using unity flash player? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges