Find specific pattern in a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ksrajalakshmi@gmail.com

    Find specific pattern in a string

    Hai ,

    in a textbox am having text as
    "(20/100)+pay1*pay2" .it's a formula. and stored in a particular
    variable.
    string strformula="(20/100)+pay1*pay2" ;

    i've to substitute the value of the variable 'pay1' & 'pay2' and
    finding the value of that strformula.
    can any onr tell me how to find 'pay1' and 'pay2' in the variable
    strformula. it's urgent and reply immediately.
    Thanks in advance.

  • Cor Ligthert [MVP]

    #2
    Re: Find specific pattern in a string

    Hi,

    I would use expect

    string strformula = "(20/100)+pay1*pay2" .Replace("pay1" ,"Whatever" ;
    strformula = strformula.Repl ace("pay2",What ever");

    However this is a VBNet newsgroup, so next time please in VBNet language
    code

    I hope this helps,

    Cor


    Comment

    • ksrajalakshmi@gmail.com

      #3
      Re: Find specific pattern in a string

      am using c#.net. however, i converted that formula to value. am getting


      "(20/100)+2323.56*43 54.56".

      if i've to get the value in double. how to proceed?

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Find specific pattern in a string

        Ksrajalak,
        [color=blue]
        > am using c#.net. however, i converted that formula to value. am getting[/color]

        Why are you than asking questions in a VB.Net newsgroup.

        Maybe you trust us more, however we are sure that the ones in the C#
        newsgroup can answer your question as well. That I answered, was already
        wrong.

        That can give problems for persons who are searching this newsgroup.

        Therefore please ask this question in the newsgroup with almost the same
        name as this however than at the end Csharp

        Thanks,

        Cor


        Comment

        • Cerebrus99

          #5
          Re: Find specific pattern in a string

          He He ! There you have it ! Mr. Ligthhert is a strict taskmaster ! ;-)



          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Find specific pattern in a string

            <ksrajalakshmi@ gmail.com> schrieb:[color=blue]
            > am using c#.net. however, i converted that formula to value. am getting
            >
            > "(20/100)+2323.56*43 54.56".
            >
            > if i've to get the value in double. how to proceed?[/color]

            MathLib
            <URL:http://www.palmbytes.d e/content/dotnet/mathlib.htm>

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            • Homer J Simpson

              #7
              Re: Find specific pattern in a string


              <ksrajalakshmi@ gmail.com> wrote in message
              news:1139642314 .576198.28610@g 44g2000cwa.goog legroups.com...[color=blue]
              > Hai ,
              >
              > in a textbox am having text as
              > "(20/100)+pay1*pay2" .it's a formula. and stored in a particular
              > variable.
              > string strformula="(20/100)+pay1*pay2" ;
              >
              > i've to substitute the value of the variable 'pay1' & 'pay2' and
              > finding the value of that strformula.
              > can any onr tell me how to find 'pay1' and 'pay2' in the variable
              > strformula. it's urgent and reply immediately.[/color]

              In VB,

              Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
              System.EventArg s) Handles Button1.Click
              Dim pay1 As Double, pay2 As Double
              Dim MySrc As String
              pay1 = 2323.56
              pay2 = 4354.56
              MySrc = TextBox1.Text
              MySrc = Replace(MySrc, "pay1", pay1.ToString)
              MySrc = Replace(MySrc, "pay2", pay2.ToString)
              TextBox2.Text = MySrc
              End Sub

              will do the replacement. However calculating the value is a whole other
              ballgame. This is "evaluating the expression" and is a well known problem in
              computer science. It is not trivial. Why don't you use Excel instead?



              Comment

              Working...