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 Firedan1176 · Apr 17, 2014 at 01:00 AM · stringssplitseparatecommandsadministrator

How to separate parts of a string?

Let's say I have a string that a player in my game can enter. He can enter the following:

kill SomePlayer123

tp SomePlayer123 AnotherPlayer123

spawn SomePlayer123

giveWeapon SomePlayer123 RandomPistol

My question isn't about how to get killing and teleporting and spawning to work, but my question is how can I separate the player's name from the command? I looked up compoundString.Split, but the thing is, tp and giveWeapon require 3 components. I know I could just separate based on spacebar, but what if the player's name has a spacebar? Should I just make it where you can't use spacebar as a name?

Finally, besides all that, what can I use to check if the player types 'kill' in general? Like if they type 'kill SomePlayer123', what will check to see if they typed kill in the first place? Wouldn't be *, would it? Thanks. Sorry for my stupidity.

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
2
Best Answer

Answer by supernat · Apr 17, 2014 at 01:13 AM

I'm not sure what compoundString is, but in C#, you would do it like this:

 string xyz = "string1 string2 string3";
 string[] array = xyz.Split(' ');
 foreach (string token in array) {
     // Parse the commands
 }

You don't HAVE to prevent the player from having a space in their name. I mean you could get around that by doing some simple logic. For instance, if your command takes 3 parameters, but you see 4, you know the first one is the command, so take the 2nd parameter, look for it in the player array of names, and if it doesn't exist, append the 3rd parameter to it, and look again. If it does exist, take the 3rd parameter and do the same thing, and if the name does exist (just the 3rd param), then the 4th parameter is an error. It can start slowing your code down if you allow any number of spaces, but if its just a first/last name type thing, then it probably wouldn't impact it that much.

There's really no simple way to handle it, other than prevent them from using spaces.

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

What can I use to find part of a phrase in a string? 2 Answers

RPC calls with Photon Networking and 'Admin Commands'??? 2 Answers

Breaking up a string every A,B,C,D and store value behind it 3 Answers

How to break up a number into seperate digits? 2 Answers

different angles same time. 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