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 8633171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:27:11+00:00 2026-06-12T09:27:11+00:00

My code dynamically generates string/number operations. The program dynamically builds something similar to the

  • 0

My code dynamically generates string/number operations. The program dynamically builds something similar to the following:

"My name " + "is " + "G-Man"
"Your age is " + "21"
"5" * "5"

I want to output this:

My Name is G-Man
Your age is 21
25

I can write a library for this, but I currently am under time constraints. If anyone aware of a library that can perform equations similar to above (int + int = int), (string + int = string), etc.?

  • 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-12T09:27:12+00:00Added an answer on June 12, 2026 at 9:27 am

    I think you probably just want to use JavaScript’s built in EVAL function.

    var a = eval("5 + 5");
    console.log(a); // >> 10
    

    EDIT Wow I got 2 down-votes at almost robotic speed when I answered this question ~weird, but again EVAL is probably what you want.

    var a = eval("'Your age is ' + '22'");
    console.log(a); // >> Your age is 22 
    

    EDIT 2 Here’s a starting point for doing some quick validation of the input to make sure nothing naughty gets Eval’d.

    var test1 = [
    "testing"
    ,"+"
    ,"123"
    ];
    var test2 = [
    "8"
    ,"*"
    ,"5"
    ,"/"
    ,"3"
    ];
    var test3 = [
    "window.alert('bad');"
    ];
    var test4 = [
    "\"It's hard to escape things\", said "
    ," + "
    ,"Bob"
    ];
    
    function supereval(arr) {
        var sEval = '';
        for(var i=0; i<arr.length; i++) {
            if(!isNaN(parseFloat(arr[i])) && isFinite(arr[i])) { // number
                sEval += arr[i];
    //console.log("> number");
            } else if( /^\s?[\+\/\*\-]\s?$/i.test(arr[i]) ) { // operation
                sEval += arr[i];
    //console.log("> operation");
            } else { // string
                sEval += "\"" + arr[i].replace(/"/g, '\\"') + "\"";
    //console.log("> string");
            }
        }
    console.log("DEBUG:" + sEval);
        return eval(sEval);
    }
    
    console.log(supereval(test1));
    console.log(supereval(test2));
    console.log(supereval(test3));
    console.log(supereval(test4));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed to dynamically generate a string like the following: 001 / 192 However
I have a piece of code that generates a csv file dynamically. The user
I have a trivia page that is dynamically generated by some javascript code. It
html code meta tag description, it is generated dynamically and we have quotes in
I know instrumentation is a technique to add trace code dynamically into the methods
I have some code that dynamically creates a new button through JavaScript that when
I have code that dynamically load 10 different textfields in viewdidload method now if
so this code here dynamically adds buttons to my wpf windows application. I cant
I have code to dynamically allocate an array of 100 doubles to a pointer
I'm creating a table in an asp.net code behind dynamically, and I want to

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.