Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Frenzikk · Nov 05, 2015 at 06:47 AM · vector3strings

Split string into three pieces?

I am working on sending multiplayer packets, and I am sending each player a message containing : "x[PLAYER POSITION X]y[PLAYER POSITION Y]z[PLAYER POSITION Z]". (Replace the brackets with the actual positions)

I want to make a vector from this information, but I am not skilled at working with string functions.

How would I put this info into a Vector3?

(C# ONLY PLEASE)

Thank you, Bryce

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

1 Reply

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

Answer by ARKMs · Nov 05, 2015 at 08:29 AM

I have this code maybe help you:

 void Start()
     {
         //packed
         float[] pos = {transform.position.x, transform.position.y, transform.position.z};
         string posINstring = Joinsfloats(pos);
         print(posINstring);
 
         //read packed
         float[] newpos = Split_floats(posINstring);
         transform.position = new Vector3(newpos[0], newpos[1], newpos[2]);
         print(transform.position);
     }
 
     public string Joinsfloats(float[] ar)
     {
         return System.String.Join("_", new List<float>(ar).ConvertAll(i => i.ToString()).ToArray());
     }
 
     public float[] Split_floats(string tx)
     {
         List<float> lista = new List<float>();
         int lasti = 0;
         while (lasti < tx.Length)
         {
             int index = tx.IndexOf('_', lasti);
             if (index != -1)
             {
                 float num = float.Parse(tx.Substring(lasti, index - lasti));
                 lista.Add(num);
                 lasti = index + 1;
             }
             else
             {
                 float num = float.Parse(tx.Substring(lasti, tx.Length - lasti));
                 lista.Add(num);
                 lasti = tx.Length;
             }
         }
         return lista.ToArray();
     }
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 Frenzikk · Nov 05, 2015 at 04:51 PM 0
Share

No. It won't work for my situation. Thank you, but I need to split the string.

avatar image ARKMs · Nov 05, 2015 at 05:47 PM 0
Share

In my function 'Split_floats()', split a string like this "50_10_30" in 3 floats, in you case, you can adapt it for split with '[' and ']'.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Look Rotation Viewing Vector is Zero 0 Answers

Unity Hanging when Changing a Vector3.x 2 Answers

How to make object land on certain point?,How to make object land on certain point?? 0 Answers

instantiate keeps repeating itself 0 Answers

How to Stack, Shuffle and deal cards 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