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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:55:27+00:00 2026-06-17T17:55:27+00:00

I have strings like following: [Current.Age] – 10 [Current.Height] + 50 [Current.Age] + 10

  • 0

I have strings like following:

"[Current.Age] - 10"
"[Current.Height] + 50"
"[Current.Age] + 10 - [Current.Height] - 50"

And I’d like to replace [Current.Something] with the numerical value of the current selected object, for example a selected object may have the following state:

var student = new Student();
student.Age = 20;
student.Height = 180;

So, the strings should end up like:

"20 - 10"             * or better *  "10"
"180 + 50"            * or better *  "230"
"20 + 10 - 180 - 50"  * or better *  "-200"

I think I should use regular expressions for this. Any ideas as to how I can accomplish this?

Edit: What I need is pretty much something that can take [Current.Something]s and replace them with relevant values. I know I can do it with simple string operations but I just wonder if there’s a short way to do this.

  • 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-17T17:55:29+00:00Added an answer on June 17, 2026 at 5:55 pm

    If you have control of the class that contains the value; you can just add a method called:

    int getValue(string fromThis)
    {
        switch(fromThis)
        {
        case "age": {....
    }
    

    Then you need to run the text through a text parser (you should be able to create onc fairly easily).

    Something like:

    string[] newStrings = newString.Split(' ');
    if (newStrings.Length < 3)
    {
        //error
    }
    else if (newStrings[0][0] != '[')
    {
        //error
    }
    else
    {
        int newValue = 0;
                    string fieldString = newStrings[0];// Extract just the part you need.... 
                    // I would probably do the above in a method 
        int currentValue = getValue(fieldString);
        int changeValue;
        int.TryParse(newStrings[2], out changeValue);
    
        switch (newStrings[1])
        {
            case "+":
                {
                    newValue = currentValue + changeValue;
                    break;
                }
            case "-":
                {
                    newValue = currentValue - changeValue;
                    break;
                }
            default:
                {
                    //error
                    break;
                }
        }
    
        //do something with new value
    }
    

    There would be more work for determining what to do for connected statements, but the above should get you going in the right direction. There are slightly cleaner ways to do this using reflection but it’s harder to maintain.

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

Sidebar

Related Questions

Suppose I have strings like the following : OneTwo ThreeFour AnotherString DVDPlayer CDPlayer I
My current regex is /[$]([a-zA-Z0-9_\-\,:]*)[$]/ and this will allow me to replace strings like
I have code something like the following: <OperationContract()> <Description()> <WebGet(Bodystyle:=WebMessageBodyStyle.Bare, UriTemplate:=TestConnection)> Function TestConnection() As
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
I have a string like the following: $string = <paragraph>apples are red...</paragraph> <paragraph>john is
I have a string like the following: String str = 4*5; Now I have
I have a string like the following: <br><b>224h / 15.45 verbuchte Stunden</b> I want
Assume we have a string like the following : ,34,23,4,5,634,23,12,5,4,3,1234,23,54,,,,,,,123,43,2,3,4,5,3424,,,,,,,,123,,,1234,,,,,,,45,,,56 How can we convert
I have a string line like the following : A:B:C:D:E:F:G:H:I:J:K:L:M It means delimiter (
I have a string that is formatted like the following: ... {{word1}} {{word2}} ....

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.