Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:34:57+00:00 2026-06-14T19:34:57+00:00

I need to assign a formula like square perimeter (4*a) which i have stored

  • 0

I need to assign a formula like square perimeter (4*a) which i have stored in resource xml as string, to a value in my activity. So, it should look like:

Activity:

int a = (formula from xml)

And XML:

<resources>

<string name="square_perimeter">4*a</string>

</resources>

Is there a way how to do that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:34:58+00:00Added an answer on June 14, 2026 at 7:34 pm

    What is [34 20 2A 20 31 36]?

    It is what a computer will see when it encounters the string "4 * 16". And just like you, when given only that, it does not know why those cryptic numbers should be equivalent to 64.

    So to really evaluate that, a computer / the algorithm would start by separating the input into chunks. Let’s assume your expression must be separated by whitespace (4*4 is illegal, 4 * 4 is okay). Based on that knowledge we can split the expression into [34], [2A], [31 36].

    • [34] stands for the character 4 which is a number => that part means 4
    • [2A] stands for the character * which is a mathematical operator => we need to multiply the part before this with the part after this.
    • [31 36] stands for 1 and 6, both are numbers. => calculate 1 * 10 + 6 => it’s a 16.

    We know at that point that a multiplication has to be done and that we have 4 and 16, so 4*16 can be calculated and we have the result.

    If you just need very simple formulas that follow strict rules, like only “[numbers] [*/+-] [numbers]” then writing a small parser for that is quite simple.

    But math gets complex pretty quickly and already “10 + 5 * 2” requires that you don’t add 10 + 5 if you evaluate from left to right because it would be the wrong result.

    The amount of code one needs to write to evaluate complex expression with variables like "5a^2 * sin(a) +1" is pretty big therefore. It needs to cover all the mathematical rules and all the special cases.


    Back to your problem: If you really want to use text formulas, look for a library that can do the ugly stuff for you. Evaluating a math expression given in string form for example mentions some.

    If you don’t need to have the formula as text you could maybe do it like this:

    You put names for methods in the xml database and implement the solution for that method in your app. The user selects a method by it’s name and you call the right method based on that name. The disadvantage is that all your formulas must be known so you can write a piece of code that can solve it.

    Very basic example:

    public int calculate(String method, int value1, int value2) {
        if ("square".equals(method)) {
            return value1 * value1;
        } else if ("add".equals(method)) {
            return value1 + value2;
        } else if ("substract".equals(method)) {
            return value1 - value2;
        } else {
            return 0;
        }
    }
    

    The values used in the formula need to come somewhere too, I don’t know how you plan to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why I always need to assign a value to string variable, before actually using
I have a string of different 3 letter words: catdogmattabratliematdogatt I need to assign
I use C#. I need assign a value to a string as verbatim .
I have a requirement where I need to assign some resource for some tine
I need to assign a variable which will be used to create the id
I need to assign constant value in integer (or other data type). I got
I need to assign value from viewbag as one of the attribute of javascript
I often need to assign a variable, if the source value is set. So
I am looking to develop a system in which i need to assign every
I need to assign many date value based on one date value by incrementing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.