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 BDX777 · Mar 18, 2015 at 08:55 AM · textstringsave datavaluesaveload

Reading integer value from specified character(s) on text line?

Hi, I'm trying to figure out how to get the 1 out of "player_skilldata_Standard Weapons=1;" (Value example)

How do I go about doing this? Perhaps I could use "=" as a start and ";" as an end, but how? I'm close to creating a saving/loading system with serialized values, and I just need to figure out how to load the values back into the game.

Comment
Add comment
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

2 Replies

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

Answer by HarshadK · Mar 18, 2015 at 09:32 AM

You can do it using the method below. It is taken from this question on Stack Overflow: How do I extract text that lies between parentheses

 public string GetNestedString(string str, char start, char end)
 {
     int s = -1;
     int i = -1;
     while (++i < str.Length)
         if (str[i] == start)
         {
             s = i;
             break;
         }
     int e = -1;
     while(++i < str.Length)
         if (str[i] == end)
         {
             e = i;
             break;
         }
     if (e > s)
         return str.Substring(s + 1, e - s - 1);
     return null;
 }

When you call the above method just pass argument parameters as below:

 string value = GetNestedString("player_skilldata_Standard Weapons=1;", '=', ';');

This will return a string representation of "1", which is the desired value which you can then convert to an integer using:

 int weaponValue = Int32.Parse(value);

You can also use Int32.TryParse instead of Int32.Parse to avoid being thrown an exception.

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 BDX777 · Mar 18, 2015 at 11:20 AM 0
Share

This is a nice answer, I had to tweak it due to a problem where I am unable to call certain commands inside of my static load method.

I'd love to share the results here, but there is a character limit.

Remember to establish the SaveSystemValues with your own serialized list of skills, inventory items, (etc) before saving or loading, otherwise you won't get any result.

avatar image
1

Answer by raulrsd · Mar 18, 2015 at 09:43 AM

You could try this instruction:

 string s = "player_skilldata_Standard Weapons=1;";
 s = s.Substring(s.IndexOf('=')+1,s.IndexOf(';')-s.IndexOf('=')-1);
 

And just in case you want convert the string number to float:

 float f = float.Parse(s);
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

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

21 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

Related Questions

My HighScore Stuck on a ceratin value and wont update.(in game HighScore works, only problem when game is restarted the value of highscore is fixed) 0 Answers

GUI text label using variable values and text 1 Answer

How can I detecting whether certain characters appear in any strings in my array of strings? 1 Answer

How to put each line of a text file into a separate sring c# 1 Answer

Best way to manage stats in a text file 2 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