tabnation

math string test

Mar 4th, 2022 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1.  
  2. f1::
  3. clipboard = "5+6/2"
  4. StringReplace, clipboard, clipboard, ",, All ;remove "
  5.  
  6. ;change math sysmbols to help with regex
  7. StringReplace, seconddigit, clipboard, +, plus, All
  8. StringReplace, thirddigit, clipboard, /, divide, All
  9. StringReplace, thirddigit, clipboard, -, minus, All
  10.  
  11. ;sort data
  12. RegExMatch(seconddigit,"is)(?<=plus)\S+",seconddigit)
  13. firstdigit := SubStr(clipboard, 1 , 1)
  14. clipboard = %firstdigit%
  15. val := seconddigit + firstdigit
  16. msgbox, %val%
  17. Return
  18.  
  19. f2::
  20. FileRead, themath, %A_Desktop%\mathtest.txt
  21. StringReplace, themath, themath, ",, All
  22. StringReplace, themath, themath, =,, All
  23. answer := Eval(themath)
  24. msgbox, %answer%
  25. return
  26.  
  27. Eval(Expr, Format := FALSE)
  28. {
  29. static obj := "" ; par cuestiones de rendimiento
  30. if ( !obj )
  31. obj := ComObjCreate("HTMLfile")
  32.  
  33. Expr := StrReplace( RegExReplace(Expr, "\s") , ",", ".")
  34. , Expr := RegExReplace(StrReplace(Expr, "**", "^"), "(\w+(\.*\d+)?)\^(\w+(\.*\d+)?)", "pow($1,$3)") ; 2**3 -> 2^3 -> pow(2,3)
  35. , Expr := RegExReplace(Expr, "=+", "==") ; = -> == | === -> == | ==== -> == | ..
  36. , Expr := RegExReplace(Expr, "\b(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2)\b", "Math.$1")
  37. , Expr := RegExReplace(Expr, "\b(abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\b\(", "Math.$1(")
  38.  
  39. , obj.write("<body><script>document.body.innerText=eval('" . Expr . "');</script>")
  40. , Expr := obj.body.innerText
  41.  
  42. return InStr(Expr, "d") ? "" : InStr(Expr, "false") ? FALSE ; d = body | undefined
  43. : InStr(Expr, "true") ? TRUE
  44. : ( Format && InStr(Expr, "e") ? Format("{:f}",Expr) : Expr )
  45. }
  46. exitapp
  47.  
  48.  
  49.  
  50.  
  51.  
Add Comment
Please, Sign In to add comment