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

  • Home
  • SEARCH
  • 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 370415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:00:56+00:00 2026-05-12T14:00:56+00:00

Is there any way to parse a string in vb.net (like, built in methods),

  • 0

Is there any way to parse a string in vb.net (like, built in methods), that can do math like Eval can? For example, 3+(7/3.5) as a string would return 2.

I am not asking for you to code this for me, I just want to know if there is a built in way to do this, if there is not I will code it myself.

I can wager that it would not be able to parse stuff like Sin(90) on its own, and I understand that would need to be replaced by Math.Sin(90).

If there is a built in method, how do you use it?

  • 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-05-12T14:00:56+00:00Added an answer on May 12, 2026 at 2:00 pm

    There’s a shortcut for limited (ie. simple) math expressions by using the DataTable.Compute method. Obviously, this isn’t robust (limited functionality) and feels hackish to misuse the DataTable for this purpose, but I figured I would add to the current answers.

    Example:

    var result = new DataTable().Compute("3+(7/3.5)", null); // 5
    

    “Sin(90)” wouldn’t work with this approach. Refer to the DataColumn.Expression Property page for a list of supported functions, specifically under the “Aggregates” section.

    Using the System.CodeDom namespace is an option.

    Some helpful links:

    • CodeDom Calculator
    • Evaluating mathematical expressions using CodeDom
    • Related SO question: Is there a string math evaluator in .NET?

    EDIT: to address your comment, here is an approach to demonstrate replacing trigonometric functions with their equivalent Math class methods.

    C#

    string expression = "(Sin(0) + Cos(0)+Tan(0)) * 10";
    string updatedExpression = Regex.Replace(expression, @"(?<func>Sin|Cos|Tan)\((?<arg>.*?)\)", match =>
                match.Groups["func"].Value == "Sin" ? Math.Sin(Int32.Parse(match.Groups["arg"].Value)).ToString() :
                match.Groups["func"].Value == "Cos" ? Math.Cos(Int32.Parse(match.Groups["arg"].Value)).ToString() :
                Math.Tan(Int32.Parse(match.Groups["arg"].Value)).ToString()
            );
    var result = new DataTable().Compute(updatedExpression, null); // 10
    

    VB.NET

    Dim expression As String = "(Sin(0) + Cos(0)+Tan(0)) * 10"
    Dim updatedExpression As String = Regex.Replace(expression, "(?<func>Sin|Cos|Tan)\((?<arg>.*?)\)", Function(match As Match) _
            If(match.Groups("func").Value = "Sin", Math.Sin(Int32.Parse(match.Groups("arg").Value)).ToString(), _
            If(match.Groups("func").Value = "Cos", Math.Cos(Int32.Parse(match.Groups("arg").Value)).ToString(), _
            Math.Tan(Int32.Parse(match.Groups("arg").Value)).ToString())) _
            )
    Dim result = New DataTable().Compute(updatedExpression, Nothing)
    

    Note, however, that you need to know the contents of the “arg” group. I know they are ints, so I used Int32.Parse on them. If they are a combination of items then this simple approach won’t work. I suspect you will constantly need to band-aid the solution if it gets too complicated with more unsupported function calls, in which case the CodeDom approach or others may be more suitable.

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

Sidebar

Ask A Question

Stats

  • Questions 170k
  • Answers 170k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC… May 12, 2026 at 2:01 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure it is necessarily the right way to… May 12, 2026 at 2:01 pm
  • Editorial Team
    Editorial Team added an answer Does this clear it up? // path1 and path2 point… May 12, 2026 at 2:01 pm

Related Questions

I'm building a generic ASP.NET server control that has an attribute used to specify
I need to maintain a legacy VB.NET web application. Data typing is, I would
I am new here so first of all my greetings to you I am
Is there any way to parse a string in the format HH:MM into a
I've been trying to create a parser using simpleparse. I've defined the grammar like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.