Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 StuwuStudio · May 05, 2016 at 09:10 PM · functionstringsearchcalculateingame

Find First Parentheses in String

Hey guys, I'm currently working in an "in game" programming game. What i need is find text in the first parenthese the script found. Here's an example: "((990 / 71) - 3^4.5) + 2 * (36.1 / 44.8 - (76.93 + 9.5))" should be returning this string "((990 / 71) - 3^4.5)". Tell my if you don't understand, i speak french. I have tried many possibility and here's what i found which can be useful: First, find the first index of "(" after find the first index of ")". If there's an other "(" between "(" and ")", like this: "(exemple()", the code need to find the next index of ")", like this "(exemple()example)". I know this the worst question...

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 Owen-Reynolds · May 06, 2016 at 03:02 AM 0
Share

Better to look in non-Unity sources. This is a well-known (but tricky) topic, and any answers you find will work just fine inside Unity.

Try searches about representing expressions. I'd guess finding matching parens is also common, but won't be good enough for what you need.

2 Replies

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

Answer by Briksins · May 05, 2016 at 11:44 PM

Hi, that should help:

 string expression = "((990 / 71) - 3^4.5) + 2 * (36.1 / 44.8 - (76.93 + 9.5))";
 int match = 0;
 var finalExpression = new StringBuilder();
 
 foreach (var character in expression.ToCharArray(0, expression.Length))
 {
     if (character == '(')
         match++;
 
     if (character == ')')
         match--;
 
     finalExpression.Append(character);
     if (match == 0)
         break;
 }
 
 Debug.log(finalExpression.ToString());

Comment
Add comment · Show 6 · 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 StuwuStudio · May 06, 2016 at 11:53 AM 0
Share

I will test this out an try if it work.

avatar image StuwuStudio · May 06, 2016 at 11:58 AM 0
Share

The script don't find StringBuilder. Is it normal?

avatar image Briksins StuwuStudio · May 06, 2016 at 12:03 PM 0
Share

it needs to be imported

avatar image StuwuStudio Briksins · May 06, 2016 at 03:51 PM 0
Share

Ohhh... I just realize how this script work. I will try to replicate without StringBuild. Thanks again!

Show more comments
avatar image
1

Answer by FortisVenaliter · May 05, 2016 at 09:18 PM

You should represent the equations as trees. Check out this StackOverflow question, that has a basic primer for how to think about it. It's for Java, but the terms are pretty universal.

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 StuwuStudio · May 06, 2016 at 11:52 AM 0
Share

I will try search about that. 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

42 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 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

Problem with Contains 0 Answers

Cannot convert 'String' to 'Array'. 2 Answers

Use transform calculating string to boolean 1 Answer

Pick a random string from a string array C# 1 Answer

use the tag of a gameobject to assign a string variable 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