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
2
Question by kubci98 · Jan 07, 2015 at 01:41 PM · stringsplit

StringSplitOptions.RemoveEmptyEntries - Unknown identifier

Hello, I am using a String to save scores for my levels (PlayerPrefs). As PlayerPrefs doesn't work with arrays, I just convert all of these into one String to this form: "LVL1score;LVL2score;LVL3score;" and so on.

However, when I try loading from it and spliting it with this code:

 prefText = PlayerPrefs.GetString("Levels");
 var lvlTexts = prefText.Split(";"[0], StringSplitOptions.RemoveEmptyEntries);
 var j : int = 0;
 for (lvlInfo in lvlTexts) {
     levels[j].levelUnlocked = (lvlInfo[0] == "Y") ? true : false;
     levels[j].levelFinished = (lvlInfo[1] == "Y") ? true : false;
     levels[j].levelScore = int.Parse(lvlInfo.Substring(2, lvlInfo.length - 2));
     j++;
 }


i get an error "Unknown identifier 'StringSplitOptions' (i need it to not include "" String after last semicolon). I have tried using import System in the beginning of script, i have tried using System.StringSplitOptions.RemoveEmptyEntries, but nothing work. I have decided to just remove last character in String, which works, but I would still like to understand, why the code above doesn't work. Thanks in advance.

Comment
Add comment · Show 1
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 tanoshimi · Jan 07, 2015 at 01:53 PM 0
Share

This was asked some time ago at http://forum.unity3d.com/threads/mono-c-string-split-question.17348/ too. And it's not listed in the $$anonymous$$ono site under System, so maybe they just didn't incorporate it?

Which is odd, because it's on the GitHub repo...

2 Replies

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

Answer by Baste · Jan 07, 2015 at 06:34 PM

Unity works with a (very, very) old version of Mono, for somewhat esoteric reasons (you can search around if you are curious). This means, among other things, that some methods that's available in modern versions of C# - either .NET or modern Mono - are not available in Unity.

My guess is that StringSplitOptions.RemoveEmptyEntries is one of those. Which means you have to do this the old fashioned way: either ignoring empty strings in your loop, or removing them beforehand.

Comment
Add comment · Show 1 · 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 GameVortex · Jan 08, 2015 at 08:48 AM 0
Share

Sure that is true, some newer methods is not available in Unity, but System.StringSplitOptions is not one of them. It is available. I have used it a lot when parsing text. The problem is actually that System.StringSplitOptions does not work with the specific version of the .Split function OP is trying to use.

avatar image
8

Answer by GameVortex · Jan 08, 2015 at 08:55 AM

The .Split function you are using does not take StringSplitOptions as a parameter. So without System. in front you get the regular Unknown Identifier, but with it you would get Invalid Arguments.

When you supply the char to split with directly then you are using the .Split function which only takes an optional number of char values to split with.

To use the .Split function which can take the StringSplitOptions you have to supply your char values as an array:

 string stringToSplit = "";
 char[] splitters = { ';' };
 string[] splittedString = stringToSplit.Split(splitters, System.StringSplitOptions.RemoveEmptyEntries);
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 Tropicaya · Jul 22, 2015 at 11:33 AM 0
Share

Awesome. I was so close. But I gave up, then decided to search. Thanks, GameVortex

avatar image luislodosm · Feb 11, 2017 at 12:14 AM 0
Share

It worked, thanks!

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

27 People are following this question.

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

Related Questions

Unity JS Equivalent of split()? 2 Answers

How to split String? 1 Answer

Skip empty strings after split 3 Answers

What do you say the best way to store a string be? 2 Answers

Trying to parse Facebook FQL response with String.Split in webplayer; no luck 1 Answer


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