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
1
Question by MonkeyAssassin8 · Mar 03, 2011 at 10:34 AM · characterstringcheck

Is there a symbol which means 'any character'?

this is kinda hard to explain, but i want my script to see if there is a string which has a certain name (eg. "Weapon") and then see if there is a character next to it (eg. "Weapon0", "Weapon1", etc) i know if you search something in windows file browser, you can type * or something after the word and it will find anything which has that word plus another character or so. If someone can make sense of this and knows how to do this it would be appreciated.

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

3 Replies

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

Answer by Statement · Mar 03, 2011 at 10:39 AM

  • You can use regular expressions for this.
  • .NET has System.Text.RegularExpressions namespace for this task.
  • You can also do a simple name.Contains("Weapon") or name.StartsWith("Weapon") (thx @yoyo).

A sample regex to find Weapon and any other characters following it could look like:

string pattern = "^Weapon.*$"

To get you started understanding regex, that regex means, "At the start of the string, there must be the string Weapon, followed by any character (the dot), zero or more times (the asterix), followed by end of string.

This pattern would match

  • Weapon (Since it starts with Weapon, and have zero other characters after it)
  • Weapon0 (Since it starts with Weapon, and have one other character after it)
  • WeaponFoobar (Since it starts with Weapon, and have six other characters after it)

But would not match

  • 6Weapon (Since it doesn't start with Weapon)
  • Weapo15 (Since it doesn't start with Weapon, but Weapo)
  • FooWeaponBar (Since it doesn't start with Weapon)

string.Contains would match 6Weapon and FooWeaponBar since it contains the string "anywhere".

string.StartWith would work just as the regex described above. It would accept any string that start with the string passed in. Kudos to yoyo for pointing this out.

Comment
Add comment · Show 3 · 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 poncho · Mar 03, 2011 at 02:56 PM 0
Share

indeed a good answer, thumbing you up

avatar image yoyo · Mar 03, 2011 at 04:09 PM 2
Share

yep, nice one. One $$anonymous$$or addition -- name.StartsWith("Weapon") and name.EndsWith("Weapon") can come in handy too.

avatar image MonkeyAssassin8 · Mar 04, 2011 at 08:08 AM 0
Share

Thank you yoyo! that works perfectly!

avatar image
0

Answer by Aldwoni_legacy · Mar 03, 2011 at 10:36 AM

You can count the amount of characters. If all names have Weapon in it you just need to check if there are more then 6 characters or not.

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 Meltdown · Mar 03, 2011 at 10:38 AM

If you are scripting in C#, do a google search for Regular Expressions C# While it is a little complex in the beginning to understand, you can do all your checks with them.

Comment
Add comment · Show 3 · 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 Statement · Mar 03, 2011 at 11:41 AM 0
Share

Does it have to be C#?

avatar image Meltdown · Mar 03, 2011 at 04:34 PM 0
Share

No, you can use RegExp in Javascript too Check out.. http://www.javascriptkit.com/javatutors/redev2.shtml

avatar image Statement · Mar 03, 2011 at 05:39 PM 0
Share

I mean, can't you use the regular expressions in .net/mono?

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

No one has followed this question yet.

Related Questions

using array functions on a string? 1 Answer

changing GUI Button text with a string array 2 Answers

How to delete the last character of a string 3 Answers

String - Replace Letters With Numbers 1 Answer

Referencing private string for array name 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