A simple find-and-replace to convert inches to centimeters using a single ExpressionTransformer rule.
ID: 1354
using uCalcSoftware;
var uc = new uCalc();
// Get the transformer that pre-processes expressions.
var t = uc.ExpressionTransformer;
// Define a rule to find "X in to cm" and replace it with the calculated value.
// Note: 'val' is captured as text and must be converted to a number with Double().
t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})");
// Use the new syntax directly in an expression.
Console.WriteLine(uc.EvalStr("10 in to cm"));
25.4 using uCalcSoftware; var uc = new uCalc(); // Get the transformer that pre-processes expressions. var t = uc.ExpressionTransformer; // Define a rule to find "X in to cm" and replace it with the calculated value. // Note: 'val' is captured as text and must be converted to a number with Double(). t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})"); // Use the new syntax directly in an expression. Console.WriteLine(uc.EvalStr("10 in to cm"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Get the transformer that pre-processes expressions.
auto t = uc.ExpressionTransformer();
// Define a rule to find "X in to cm" and replace it with the calculated value.
// Note: 'val' is captured as text and must be converted to a number with Double().
t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})");
// Use the new syntax directly in an expression.
cout << uc.EvalStr("10 in to cm") << endl;
}
25.4 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Get the transformer that pre-processes expressions. auto t = uc.ExpressionTransformer(); // Define a rule to find "X in to cm" and replace it with the calculated value. // Note: 'val' is captured as text and must be converted to a number with Double(). t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})"); // Use the new syntax directly in an expression. cout << uc.EvalStr("10 in to cm") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Get the transformer that pre-processes expressions.
Dim t = uc.ExpressionTransformer
'// Define a rule to find "X in to cm" and replace it with the calculated value.
'// Note: 'val' is captured as text and must be converted to a number with Double().
t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})")
'// Use the new syntax directly in an expression.
Console.WriteLine(uc.EvalStr("10 in to cm"))
End Sub
End Module
25.4 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Get the transformer that pre-processes expressions. Dim t = uc.ExpressionTransformer '// Define a rule to find "X in to cm" and replace it with the calculated value. '// Note: 'val' is captured as text and must be converted to a number with Double(). t.FromTo("{@Number:val} in to cm", "({@Eval: Double(val) * 2.54})") '// Use the new syntax directly in an expression. Console.WriteLine(uc.EvalStr("10 in to cm")) End Sub End Module