uCalc SDK Interactive Examples

A practical, real-world example of integration: using the Transformer and Expression Parser together to create a simple template engine that replaces placeholders with evaluated data.

ID: 1359

				
					using uCalcSoftware;

var uc = new uCalc();
// Define the data context for our template
uc.DefineVariable("user = 'Alice'");
uc.DefineVariable("score = 95");

// Define the template with placeholders
var myTemplate = "User: {user}, Score: {score * 10}, Status: {IIf(score > 90, 'Excellent', 'Good')}";

var t = uc.NewTransformer();
// This single rule finds placeholders like {...}
// and uses the Expression Parser ({@@Eval}) to evaluate the content inside.
t.FromTo("'{' {expr} '}'", "{@@Eval: expr}");

Console.WriteLine(t.Transform(myTemplate));

				
			
User: Alice, Score: 950, Status: Excellent
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define the data context for our template
   uc.DefineVariable("user = 'Alice'");
   uc.DefineVariable("score = 95");

   // Define the template with placeholders
   auto myTemplate = "User: {user}, Score: {score * 10}, Status: {IIf(score > 90, 'Excellent', 'Good')}";

   auto t = uc.NewTransformer();
   // This single rule finds placeholders like {...}
   // and uses the Expression Parser ({@@Eval}) to evaluate the content inside.
   t.FromTo("'{' {expr} '}'", "{@@Eval: expr}");

   cout << t.Transform(myTemplate) << endl;

}
				
			
User: Alice, Score: 950, Status: Excellent
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define the data context for our template
      uc.DefineVariable("user = 'Alice'")
      uc.DefineVariable("score = 95")
      
      '// Define the template with placeholders
      Dim myTemplate = "User: {user}, Score: {score * 10}, Status: {IIf(score > 90, 'Excellent', 'Good')}"
      
      Dim t = uc.NewTransformer()
      '// This single rule finds placeholders like {...}
      '// and uses the Expression Parser ({@@Eval}) to evaluate the content inside.
      t.FromTo("'{' {expr} '}'", "{@@Eval: expr}")
      
      Console.WriteLine(t.Transform(myTemplate))
      
   End Sub
End Module
				
			
User: Alice, Score: 950, Status: Excellent
A practical, real-world example of using `SkipOver` to ignore HTML comments while transforming other parts of the document.

ID: 1124

See: SkipOver
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
// Disable statement sensitivity to handle multi-line content
t.DefaultRuleSet.StatementSensitive = false;

var htmlContent =
"""

<nav>
  <li><a href="#intro">Intro</a></li>
  <!-- <li><a href="#contact">Contact</a></li> -->
  <li><a href="#about">About</a></li>
</nav>

""";
t.Text = htmlContent;

// A rule to find all list items
t.Pattern("<li>{item}</li>");

// A rule to skip over HTML comments
t.SkipOver("<!-- {comment} -->");

t.Find();
Console.WriteLine("--- Found List Items ---");
Console.WriteLine(t.Matches.Text);
				
			
--- Found List Items ---
<li><a href="#intro">Intro</a></li>
<li><a href="#about">About</a></li>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   // Disable statement sensitivity to handle multi-line content
   t.DefaultRuleSet().StatementSensitive(false);

   auto htmlContent =
   R"(
<nav>
  <li><a href="#intro">Intro</a></li>
  <!-- <li><a href="#contact">Contact</a></li> -->
  <li><a href="#about">About</a></li>
</nav>
)";
   t.Text(htmlContent);

   // A rule to find all list items
   t.Pattern("<li>{item}</li>");

   // A rule to skip over HTML comments
   t.SkipOver("<!-- {comment} -->");

   t.Find();
   cout << "--- Found List Items ---" << endl;
   cout << t.Matches().Text() << endl;
}
				
			
--- Found List Items ---
<li><a href="#intro">Intro</a></li>
<li><a href="#about">About</a></li>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      '// Disable statement sensitivity to handle multi-line content
      t.DefaultRuleSet.StatementSensitive = false
      
      Dim htmlContent =
      "
<nav>
  <li><a href=""#intro"">Intro</a></li>
  <!-- <li><a href=""#contact"">Contact</a></li> -->
  <li><a href=""#about"">About</a></li>
</nav>
"
      t.Text = htmlContent
      
      '// A rule to find all list items
      t.Pattern("<li>{item}</li>")
      
      '// A rule to skip over HTML comments
      t.SkipOver("<!-- {comment} -->")
      
      t.Find()
      Console.WriteLine("--- Found List Items ---")
      Console.WriteLine(t.Matches.Text)
   End Sub
End Module
				
			
--- Found List Items ---
<li><a href="#intro">Intro</a></li>
<li><a href="#about">About</a></li>
A practical, real-world parser that handles multiple key-value pairs and URL-encoded characters using a custom callback.

ID: 1399

				
					using uCalcSoftware;

var uc = new uCalc();

static void URLDecode(uCalc.Callback cb) {
   // In a real application, this would be a full URL decoding implementation.
   // For this example, we'll just handle spaces (%20) and plus signs (+).
   uCalc.String s = cb.ArgStr(1);
   s.Replace("%20", " ").Replace("+", " ");
   cb.ReturnStr(s.Text);
}


// 1. Define the custom URLDecode function in the uCalc engine
uc.DefineFunction("URLDecode(s As String) As String", URLDecode);

// 2. Create the transformer and configure its tokenizer
using (var t = new uCalc.Transformer(uc)) {
   // Treat '&' as a statement separator to process each pair individually
   t.Tokens.Add("&", TokenType.StatementSep);

   // 3. Define the rule to capture key-value pairs and decode the value
   t.FromTo("{@Alphanumeric:key}={value}", "- {key}: '{@Eval: URLDecode(value)}'");

   // 4. Process a real-world query string
   var queryString = "name=John%20Doe&role=user+admin&id=123";

   // Use Filter() to get a clean, newline-separated list of the results
   Console.WriteLine(t.Transform(queryString).Matches);
}
				
			
- name: 'John Doe'
- role: 'user admin'
- id: '123'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call URLDecode(uCalcBase::Callback cb) {
   // In a real application, this would be a full URL decoding implementation.
   // For this example, we'll just handle spaces (%20) and plus signs (+).
   uCalc::String s = cb.ArgStr(1);
   s.Replace("%20", " ").Replace("+", " ");
   cb.ReturnStr(s.Text());
}

int main() {
   uCalc uc;
   // 1. Define the custom URLDecode function in the uCalc engine
   uc.DefineFunction("URLDecode(s As String) As String", URLDecode);

   // 2. Create the transformer and configure its tokenizer
   {
      uCalc::Transformer t(uc);
      t.Owned(); // Causes t to be released when it goes out of scope
      // Treat '&' as a statement separator to process each pair individually
      t.Tokens().Add("&", TokenType::StatementSep);

      // 3. Define the rule to capture key-value pairs and decode the value
      t.FromTo("{@Alphanumeric:key}={value}", "- {key}: '{@Eval: URLDecode(value)}'");

      // 4. Process a real-world query string
      auto queryString = "name=John%20Doe&role=user+admin&id=123";

      // Use Filter() to get a clean, newline-separated list of the results
      cout << t.Transform(queryString).Matches() << endl;
   }
}
				
			
- name: 'John Doe'
- role: 'user admin'
- id: '123'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub URLDecode(ByVal cb As uCalc.Callback)
      '// In a real application, this would be a full URL decoding implementation.
      '// For this example, we'll just handle spaces (%20) and plus signs (+).
      Dim s As uCalc.String = cb.ArgStr(1)
      s.Replace("%20", " ").Replace("+", " ")
      cb.ReturnStr(s.Text)
   End Sub
   
   Public Sub Main()
      Dim uc As New uCalc()
      '// 1. Define the custom URLDecode function in the uCalc engine
      uc.DefineFunction("URLDecode(s As String) As String", AddressOf URLDecode)
      
      '// 2. Create the transformer and configure its tokenizer
      Using t As New uCalc.Transformer(uc)
         '// Treat '&' as a statement separator to process each pair individually
         t.Tokens.Add("&", TokenType.StatementSep)
         
         '// 3. Define the rule to capture key-value pairs and decode the value
         t.FromTo("{@Alphanumeric:key}={value}", "- {key}: '{@Eval: URLDecode(value)}'")
         
         '// 4. Process a real-world query string
         Dim queryString = "name=John%20Doe&role=user+admin&id=123"
         
         '// Use Filter() to get a clean, newline-separated list of the results
         Console.WriteLine(t.Transform(queryString).Matches)
      End Using
   End Sub
End Module
				
			
- name: 'John Doe'
- role: 'user admin'
- id: '123'
A quick example demonstrating how to set and get a description on a variable.

ID: 310

				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable and chain the Description() call to set metadata
var myVar = uc.DefineVariable("x = 10").SetDescription("Stores the current iteration count.");

// Retrieve and display the description
Console.WriteLine($"Description for 'x': {myVar.Description}");
				
			
Description for 'x': Stores the current iteration count.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable and chain the Description() call to set metadata
   auto myVar = uc.DefineVariable("x = 10").SetDescription("Stores the current iteration count.");

   // Retrieve and display the description
   cout << "Description for 'x': " << myVar.Description() << endl;
}
				
			
Description for 'x': Stores the current iteration count.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable and chain the Description() call to set metadata
      Dim myVar = uc.DefineVariable("x = 10").SetDescription("Stores the current iteration count.")
      
      '// Retrieve and display the description
      Console.WriteLine($"Description for 'x': {myVar.Description}")
   End Sub
End Module
				
			
Description for 'x': Stores the current iteration count.
A quick start example showing defining a variable, a function, and evaluating an expression.

ID: 1296

				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineVariable("x = 10");
uc.DefineFunction("DoubleThis(n) = n * 2");

Console.WriteLine(uc.Eval("DoubleThis(x) + 5"));
				
			
25
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineVariable("x = 10");
   uc.DefineFunction("DoubleThis(n) = n * 2");

   cout << uc.Eval("DoubleThis(x) + 5") << endl;
}
				
			
25
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineVariable("x = 10")
      uc.DefineFunction("DoubleThis(n) = n * 2")
      
      Console.WriteLine(uc.Eval("DoubleThis(x) + 5"))
   End Sub
End Module
				
			
25
A real-world example contrasting the inefficient loop with the high-performance 'Parse-Once' pattern using a changing variable.

ID: 1193

				
					using uCalcSoftware;

var uc = new uCalc();
var x_var = uc.DefineVariable("x");
var i = 0;

// --- Inefficient Way ---
Console.WriteLine("--- Inefficient: Eval() in a loop ---");
for ( i = 1; i <= 3; i++) {
   x_var.Value(i);
   Console.WriteLine(uc.Eval("x * x + 2"));
}

Console.WriteLine("");

// --- High-Performance Way ---
Console.WriteLine("--- Efficient: Parse() once, Evaluate() in a loop ---");
// Parse outside the loop
var expr = uc.Parse("x * x + 2");
for ( i = 1; i <= 3; i++) {
   x_var.Value(i);
   // Evaluate the pre-parsed object
   Console.WriteLine(expr.Evaluate());
}
				
			
--- Inefficient: Eval() in a loop ---
3
6
11

--- Efficient: Parse() once, Evaluate() in a loop ---
3
6
11
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto x_var = uc.DefineVariable("x");
   auto i = 0;

   // --- Inefficient Way ---
   cout << "--- Inefficient: Eval() in a loop ---" << endl;
   for ( i = 1; i <= 3; i++) {
      x_var.Value(i);
      cout << uc.Eval("x * x + 2") << endl;
   }

   cout << "" << endl;

   // --- High-Performance Way ---
   cout << "--- Efficient: Parse() once, Evaluate() in a loop ---" << endl;
   // Parse outside the loop
   auto expr = uc.Parse("x * x + 2");
   for ( i = 1; i <= 3; i++) {
      x_var.Value(i);
      // Evaluate the pre-parsed object
      cout << expr.Evaluate() << endl;
   }
}
				
			
--- Inefficient: Eval() in a loop ---
3
6
11

--- Efficient: Parse() once, Evaluate() in a loop ---
3
6
11
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim x_var = uc.DefineVariable("x")
      Dim i = 0
      
      '// --- Inefficient Way ---
      Console.WriteLine("--- Inefficient: Eval() in a loop ---")
      For i  = 1 To 3
         x_var.Value(i)
         Console.WriteLine(uc.Eval("x * x + 2"))
      Next
      
      Console.WriteLine("")
      
      '// --- High-Performance Way ---
      Console.WriteLine("--- Efficient: Parse() once, Evaluate() in a loop ---")
      '// Parse outside the loop
      Dim expr = uc.Parse("x * x + 2")
      For i  = 1 To 3
         x_var.Value(i)
         '// Evaluate the pre-parsed object
         Console.WriteLine(expr.Evaluate())
      Next
   End Sub
End Module
				
			
--- Inefficient: Eval() in a loop ---
3
6
11

--- Efficient: Parse() once, Evaluate() in a loop ---
3
6
11
A real-world refactoring task to rename a function, showing how uCalc correctly ignores matches inside comments and strings by default.

ID: 1227

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
t.FromTo("get_data", "fetch_records");

var code = """

// Note: 'get_data' is the old function name.
results = get_data(source);
print("The 'get_data' function was called.");

""";

// The default tokenizer recognizes the comment and string literal as separate tokens,
// so the rule to replace the function name doesn't affect them.
Console.WriteLine(t.Transform(code));
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
   t.FromTo("get_data", "fetch_records");

   auto code = R"(
// Note: 'get_data' is the old function name.
results = get_data(source);
print("The 'get_data' function was called.");
)";

   // The default tokenizer recognizes the comment and string literal as separate tokens,
   // so the rule to replace the function name doesn't affect them.
   cout << t.Transform(code) << endl;
}
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
      t.FromTo("get_data", "fetch_records")
      
      Dim code = "
// Note: 'get_data' is the old function name.
results = get_data(source);
print(""The 'get_data' function was called."");
"
      
      '// The default tokenizer recognizes the comment and string literal as separate tokens,
      '// so the rule to replace the function name doesn't affect them.
      Console.WriteLine(t.Transform(code))
   End Sub
End Module
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");
A simple `Describe` function that uses `ByHandle` to inspect an argument's name and data type.

ID: 1236

				
					using uCalcSoftware;

var uc = new uCalc();

static void DescribeArg(uCalc.Callback cb) {
   // Retrieve the Item object for the first argument.
   var item = cb.ArgItem(1);

   // Inspect the item's metadata.
   var name = item.Name;
   if (name == "") {
      name = "(literal)";
   }

   Console.WriteLine($"  - Name: {name}, Type: {item.DataType.Name}");
}

uc.DefineFunction("Describe(ByHandle arg As AnyType)", DescribeArg);
uc.DefineVariable("my_var = 100");

Console.WriteLine("Inspecting a variable:");
uc.Eval("Describe(my_var)");

Console.WriteLine("Inspecting a literal value:");
uc.Eval("Describe(123.45)");

Console.WriteLine("Inspecting a string value:");
uc.EvalStr("Describe('abc xyz')");
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call DescribeArg(uCalcBase::Callback cb) {
   // Retrieve the Item object for the first argument.
   auto item = cb.ArgItem(1);

   // Inspect the item's metadata.
   auto name = item.Name();
   if (name == "") {
      name = "(literal)";
   }

   cout << "  - Name: " << name << ", Type: " << item.DataType().Name() << endl;
}
int main() {
   uCalc uc;
   uc.DefineFunction("Describe(ByHandle arg As AnyType)", DescribeArg);
   uc.DefineVariable("my_var = 100");

   cout << "Inspecting a variable:" << endl;
   uc.Eval("Describe(my_var)");

   cout << "Inspecting a literal value:" << endl;
   uc.Eval("Describe(123.45)");

   cout << "Inspecting a string value:" << endl;
   uc.EvalStr("Describe('abc xyz')");
}
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub DescribeArg(ByVal cb As uCalc.Callback)
      '// Retrieve the Item object for the first argument.
      Dim item = cb.ArgItem(1)
      
      '// Inspect the item's metadata.
      Dim name = item.Name
      If Len(name) = 0 Then
         name = "(literal)"
      End If
      
      Console.WriteLine($"  - Name: {name}, Type: {item.DataType.Name}")
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineFunction("Describe(ByHandle arg As AnyType)", AddressOf DescribeArg)
      uc.DefineVariable("my_var = 100")
      
      Console.WriteLine("Inspecting a variable:")
      uc.Eval("Describe(my_var)")
      
      Console.WriteLine("Inspecting a literal value:")
      uc.Eval("Describe(123.45)")
      
      Console.WriteLine("Inspecting a string value:")
      uc.EvalStr("Describe('abc xyz')")
   End Sub
End Module
				
			
Inspecting a variable:
  - Name: my_var, Type: double
Inspecting a literal value:
  - Name: (literal), Type: double
Inspecting a string value:
  - Name: (literal), Type: string
A simple `Find()` followed by `@Matches().Count()` to count all occurrences of a word.

ID: 1099

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "apple banana apple cherry apple";

// Define a pattern to find any alphanumeric word
t.Pattern("apple");
t.Find();

Console.WriteLine($"Found {t.Matches.Count()} occurrences of 'apple'.");
				
			
Found 3 occurrences of 'apple'.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.Text("apple banana apple cherry apple");

   // Define a pattern to find any alphanumeric word
   t.Pattern("apple");
   t.Find();

   cout << "Found " << t.Matches().Count() << " occurrences of 'apple'." << endl;
}
				
			
Found 3 occurrences of 'apple'.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.Text = "apple banana apple cherry apple"
      
      '// Define a pattern to find any alphanumeric word
      t.Pattern("apple")
      t.Find()
      
      Console.WriteLine($"Found {t.Matches.Count()} occurrences of 'apple'.")
   End Sub
End Module
				
			
Found 3 occurrences of 'apple'.
A simple calculation to convert a temperature from Celsius to Fahrenheit, demonstrating basic arithmetic and order of operations.

ID: 1266

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32"));
				
			
98.6
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << uc.EvalStr("(37) * (9 / 5) + 32") << endl;
}
				
			
98.6
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine(uc.EvalStr("(37) * (9 / 5) + 32"))
   End Sub
End Module
				
			
98.6
A simple cascading transformation (`A` -> `B` -> `C` -> `D`) shows the step-by-step output.

ID: 1138

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// RewindOnChange is necessary for cascading rules to be re-evaluated.
t.FromTo("A", "B").RewindOnChange = true;
t.FromTo("B", "C").RewindOnChange = true;
t.FromTo("C", "D").RewindOnChange = true;

// Trace the transformation of "A"
uCalc.String trace = t.TraceTransform("A");

// Format the output list with ' -> ' for readability
trace.ListSeparator(" -> ");

Console.WriteLine(trace);
				
			
A -> B -> C -> D
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // RewindOnChange is necessary for cascading rules to be re-evaluated.
   t.FromTo("A", "B").RewindOnChange(true);
   t.FromTo("B", "C").RewindOnChange(true);
   t.FromTo("C", "D").RewindOnChange(true);

   // Trace the transformation of "A"
   uCalc::String trace = t.TraceTransform("A");

   // Format the output list with ' -> ' for readability
   trace.ListSeparator(" -> ");

   cout << trace << endl;
}
				
			
A -> B -> C -> D
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// RewindOnChange is necessary for cascading rules to be re-evaluated.
      t.FromTo("A", "B").RewindOnChange = true
      t.FromTo("B", "C").RewindOnChange = true
      t.FromTo("C", "D").RewindOnChange = true
      
      '// Trace the transformation of "A"
      Dim trace As uCalc.String = t.TraceTransform("A")
      
      '// Format the output list with ' -> ' for readability
      trace.ListSeparator(" -> ")
      
      Console.WriteLine(trace)
   End Sub
End Module
				
			
A -> B -> C -> D
A simple check to see which uCalc instance is the default.

ID: 366

				
					using uCalcSoftware;

var uc = new uCalc();
// The implicit 'uc' object is not the default upon creation.
Console.WriteLine($"Is 'uc' the default instance? {uc.IsDefault}");

// Create a new uCalc instance. It also won't be the default.
var myCalc = new uCalc();
Console.WriteLine($"Is 'myCalc' the default instance? {myCalc.IsDefault}");

// Let's get the actual default instance and check it.
uCalc defaultInstance = uCalc.DefaultInstance;
Console.WriteLine($"Is the instance from uCalc.DefaultInstance the default? {defaultInstance.IsDefault}");
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // The implicit 'uc' object is not the default upon creation.
   cout << "Is 'uc' the default instance? " << tf(uc.IsDefault()) << endl;

   // Create a new uCalc instance. It also won't be the default.
   uCalc myCalc;
   cout << "Is 'myCalc' the default instance? " << tf(myCalc.IsDefault()) << endl;

   // Let's get the actual default instance and check it.
   uCalc defaultInstance = uCalc::DefaultInstance();
   cout << "Is the instance from uCalc.DefaultInstance the default? " << tf(defaultInstance.IsDefault()) << endl;
}
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// The implicit 'uc' object is not the default upon creation.
      Console.WriteLine($"Is 'uc' the default instance? {uc.IsDefault}")
      
      '// Create a new uCalc instance. It also won't be the default.
      Dim myCalc As New uCalc()
      Console.WriteLine($"Is 'myCalc' the default instance? {myCalc.IsDefault}")
      
      '// Let's get the actual default instance and check it.
      Dim defaultInstance As uCalc = uCalc.DefaultInstance
      Console.WriteLine($"Is the instance from uCalc.DefaultInstance the default? {defaultInstance.IsDefault}")
   End Sub
End Module
				
			
Is 'uc' the default instance? False
Is 'myCalc' the default instance? False
Is the instance from uCalc.DefaultInstance the default? True
A simple demonstration of adding a fixed offset to a match's coordinates.

ID: 849

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer().SetText("The quick brown fox jumps over.");
t.Pattern("fox");
t.Find();

var matches = t.Matches;
Console.WriteLine($"Original Start Position: {matches[0].StartPosition}");

// Add an offset of 100 to all match positions
matches.ApplyOffset(100);

Console.WriteLine($"New Start Position: {matches[0].StartPosition}");
				
			
Original Start Position: 16
New Start Position: 116
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer().SetText("The quick brown fox jumps over.");
   t.Pattern("fox");
   t.Find();

   auto matches = t.Matches();
   cout << "Original Start Position: " << matches[0].StartPosition() << endl;

   // Add an offset of 100 to all match positions
   matches.ApplyOffset(100);

   cout << "New Start Position: " << matches[0].StartPosition() << endl;
}
				
			
Original Start Position: 16
New Start Position: 116
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer().SetText("The quick brown fox jumps over.")
      t.Pattern("fox")
      t.Find()
      
      Dim matches = t.Matches
      Console.WriteLine($"Original Start Position: {matches(0).StartPosition}")
      
      '// Add an offset of 100 to all match positions
      matches.ApplyOffset(100)
      
      Console.WriteLine($"New Start Position: {matches(0).StartPosition}")
   End Sub
End Module
				
			
Original Start Position: 16
New Start Position: 116
A simple demonstration of defining a token in one transformer and reusing it in another.

ID: 1003

See: Add(Item)
				
					using uCalcSoftware;

var uc = new uCalc();
var t1 = new uCalc.Transformer();
var t2 = new uCalc.Transformer();

// Define a custom token in the first transformer
var customToken = t1.Tokens.Add("###", TokenType.Generic);

// Import the token definition into the second transformer
t2.Tokens.Add(customToken);
t2.FromTo("###", "MATCH");

Console.WriteLine($"t2 can now find '###': {t2.Transform("Test ### Test")}");
				
			
t2 can now find '###': Test MATCH Test
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t1;
   uCalc::Transformer t2;

   // Define a custom token in the first transformer
   auto customToken = t1.Tokens().Add("###", TokenType::Generic);

   // Import the token definition into the second transformer
   t2.Tokens().Add(customToken);
   t2.FromTo("###", "MATCH");

   cout << "t2 can now find '###': " << t2.Transform("Test ### Test") << endl;
}
				
			
t2 can now find '###': Test MATCH Test
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t1 As New uCalc.Transformer()
      Dim t2 As New uCalc.Transformer()
      
      '// Define a custom token in the first transformer
      Dim customToken = t1.Tokens.Add("###", TokenType.Generic)
      
      '// Import the token definition into the second transformer
      t2.Tokens.Add(customToken)
      t2.FromTo("###", "MATCH")
      
      Console.WriteLine($"t2 can now find '###': {t2.Transform("Test ### Test")}")
   End Sub
End Module
				
			
t2 can now find '###': Test MATCH Test
A simple demonstration of finding a word but only inside a specific parenthetical block.

ID: 1239

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();

// 1. Parent rule finds content inside parentheses.
var parentRule = t.FromTo("({body})", "({body})");

// 2. Get the local transformer for the parent.
var local_t = parentRule.LocalTransformer;

// 3. Child rule runs only inside the parentheses.
local_t.FromTo("this", "THIS");

var text = "do not find this, but (find this) and not this";
Console.WriteLine(t.Transform(text));
				
			
do not find this, but (find THIS) and not this
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;

   // 1. Parent rule finds content inside parentheses.
   auto parentRule = t.FromTo("({body})", "({body})");

   // 2. Get the local transformer for the parent.
   auto local_t = parentRule.LocalTransformer();

   // 3. Child rule runs only inside the parentheses.
   local_t.FromTo("this", "THIS");

   auto text = "do not find this, but (find this) and not this";
   cout << t.Transform(text) << endl;
}
				
			
do not find this, but (find THIS) and not this
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      
      '// 1. Parent rule finds content inside parentheses.
      Dim parentRule = t.FromTo("({body})", "({body})")
      
      '// 2. Get the local transformer for the parent.
      Dim local_t = parentRule.LocalTransformer
      
      '// 3. Child rule runs only inside the parentheses.
      local_t.FromTo("this", "THIS")
      
      Dim text = "do not find this, but (find this) and not this"
      Console.WriteLine(t.Transform(text))
   End Sub
End Module
				
			
do not find this, but (find THIS) and not this
A simple demonstration of how a rule's name is derived from the first token in its pattern.

ID: 951

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();

var rule1 = t.FromTo("Hello {name}", "Hi {name}");
var rule2 = t.Pattern("<h1>{title}</h1>");

Console.WriteLine($"Rule 1 Name: '{rule1.Name}'");
Console.WriteLine($"Rule 2 Name: '{rule2.Name}'");
				
			
Rule 1 Name: 'hello'
Rule 2 Name: '<'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;

   auto rule1 = t.FromTo("Hello {name}", "Hi {name}");
   auto rule2 = t.Pattern("<h1>{title}</h1>");

   cout << "Rule 1 Name: '" << rule1.Name() << "'" << endl;
   cout << "Rule 2 Name: '" << rule2.Name() << "'" << endl;
}
				
			
Rule 1 Name: 'hello'
Rule 2 Name: '<'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      
      Dim rule1 = t.FromTo("Hello {name}", "Hi {name}")
      Dim rule2 = t.Pattern("<h1>{title}</h1>")
      
      Console.WriteLine($"Rule 1 Name: '{rule1.Name}'")
      Console.WriteLine($"Rule 2 Name: '{rule2.Name}'")
   End Sub
End Module
				
			
Rule 1 Name: 'hello'
Rule 2 Name: '<'
A simple demonstration of parsing an expression and then evaluating it.

ID: 396

See: Parse
				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine("Parsing the expression '100 / 4'...");
using (var parsedExpr = new uCalc.Expression("100 / 4")) {
   //var parsedExpr = uc.Parse("100 / 4");

   Console.WriteLine("Evaluating the result...");
   Console.WriteLine($"Result: {parsedExpr.Evaluate()}");
}
				
			
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << "Parsing the expression '100 / 4'..." << endl;
   {
      uCalc::Expression parsedExpr("100 / 4");
      parsedExpr.Owned(); // Causes parsedExpr to be released when it goes out of scope
      //var parsedExpr = uc.Parse("100 / 4");

      cout << "Evaluating the result..." << endl;
      cout << "Result: " << parsedExpr.Evaluate() << endl;
   }
}
				
			
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine("Parsing the expression '100 / 4'...")
      Using parsedExpr As New uCalc.Expression("100 / 4")
         '//var parsedExpr = uc.Parse("100 / 4");
         
         Console.WriteLine("Evaluating the result...")
         Console.WriteLine($"Result: {parsedExpr.Evaluate()}")
      End Using
   End Sub
End Module
				
			
Parsing the expression '100 / 4'...
Evaluating the result...
Result: 25
A simple demonstration of parsing an expression and then manually releasing it.

ID: 601

See: Release
				
					using uCalcSoftware;

var uc = new uCalc();
var expr = uc.Parse("1 + 2");
Console.WriteLine(expr.EvaluateStr());

// Manually release the expression when it's no longer needed.
expr.Release();
				
			
3
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto expr = uc.Parse("1 + 2");
   cout << expr.EvaluateStr() << endl;

   // Manually release the expression when it's no longer needed.
   expr.Release();
}
				
			
3
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim expr = uc.Parse("1 + 2")
      Console.WriteLine(expr.EvaluateStr())
      
      '// Manually release the expression when it's no longer needed.
      expr.Release()
   End Sub
End Module
				
			
3
A simple demonstration of parsing an expression once and then evaluating it.

ID: 573

See: Evaluate
				
					using uCalcSoftware;

var uc = new uCalc();
// 1. Parse the expression into a reusable object.
var parsedExpr = uc.Parse("100 / 4");

// 2. Evaluate the pre-parsed object.
Console.WriteLine($"Result: {parsedExpr.Evaluate()}");
				
			
Result: 25
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // 1. Parse the expression into a reusable object.
   auto parsedExpr = uc.Parse("100 / 4");

   // 2. Evaluate the pre-parsed object.
   cout << "Result: " << parsedExpr.Evaluate() << endl;
}
				
			
Result: 25
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// 1. Parse the expression into a reusable object.
      Dim parsedExpr = uc.Parse("100 / 4")
      
      '// 2. Evaluate the pre-parsed object.
      Console.WriteLine($"Result: {parsedExpr.Evaluate()}")
   End Sub
End Module
				
			
Result: 25
A simple demonstration of retrieving the data type name from a defined variable.

ID: 616

				
					using uCalcSoftware;

var uc = new uCalc();
var myInt = uc.DefineVariable("myInt As Int");
var myIntType = myInt.DataType;
Console.WriteLine($"Variable 'myInt' has type: {myIntType.Name}");
				
			
Variable 'myInt' has type: int
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto myInt = uc.DefineVariable("myInt As Int");
   auto myIntType = myInt.DataType();
   cout << "Variable 'myInt' has type: " << myIntType.Name() << endl;
}
				
			
Variable 'myInt' has type: int
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim myInt = uc.DefineVariable("myInt As Int")
      Dim myIntType = myInt.DataType
      Console.WriteLine($"Variable 'myInt' has type: {myIntType.Name}")
   End Sub
End Module
				
			
Variable 'myInt' has type: int
A simple demonstration of retrieving the name from a defined variable's Item object.

ID: 644

				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable and retrieve its name from the Item object.
var myVarItem = uc.DefineVariable("MyCoolVariable = 10");
Console.WriteLine($"Item name: {myVarItem.Name}");
				
			
Item name: mycoolvariable
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable and retrieve its name from the Item object.
   auto myVarItem = uc.DefineVariable("MyCoolVariable = 10");
   cout << "Item name: " << myVarItem.Name() << endl;
}
				
			
Item name: mycoolvariable
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable and retrieve its name from the Item object.
      Dim myVarItem = uc.DefineVariable("MyCoolVariable = 10")
      Console.WriteLine($"Item name: {myVarItem.Name}")
   End Sub
End Module
				
			
Item name: mycoolvariable
A simple demonstration of safely renaming a variable without corrupting a string literal, a common pitfall for Regex.

ID: 1226

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// This rule only targets the alphanumeric token 'x'.
t.FromTo("x", "value");
var code = """
x = 5; print("The value of x is...");
""";
Console.WriteLine(t.Transform(code));
				
			
value = 5; print("The value of x is...");
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // This rule only targets the alphanumeric token 'x'.
   t.FromTo("x", "value");
   auto code = R"(x = 5; print("The value of x is...");)";
   cout << t.Transform(code) << endl;
}
				
			
value = 5; print("The value of x is...");
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// This rule only targets the alphanumeric token 'x'.
      t.FromTo("x", "value")
      Dim code = "x = 5; print(""The value of x is..."");"
      Console.WriteLine(t.Transform(code))
   End Sub
End Module
				
			
value = 5; print("The value of x is...");
A simple example demonstrating a few of the most common math, logic, and string functions.

ID: 1183

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}");
Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}");
Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}");
				
			
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << "Square root of 81 is: " << uc.Eval("Sqrt(81)") << endl;
   cout << "Is 10 greater than 5? " << uc.EvalStr("IIf(10 > 5, 'Yes', 'No')") << endl;
   cout << "String length: " << uc.Eval("Length('uCalc rocks!')") << endl;
}
				
			
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine($"Square root of 81 is: {uc.Eval("Sqrt(81)")}")
      Console.WriteLine($"Is 10 greater than 5? {uc.EvalStr("IIf(10 > 5, 'Yes', 'No')")}")
      Console.WriteLine($"String length: {uc.Eval("Length('uCalc rocks!')")}")
   End Sub
End Module
				
			
Square root of 81 is: 9
Is 10 greater than 5? Yes
String length: 12
A simple example demonstrating how to find and wrap all numeric values in a string.

ID: 1201

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// Define a rule to find any number and wrap it in 'Num(...)'
t.FromTo("{@Number:n}", "Num({n})");

Console.WriteLine(t.Transform("var x = 10.5; var y = 20;"));
				
			
var x = Num(10.5); var y = Num(20);
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // Define a rule to find any number and wrap it in 'Num(...)'
   t.FromTo("{@Number:n}", "Num({n})");

   cout << t.Transform("var x = 10.5; var y = 20;") << endl;
}
				
			
var x = Num(10.5); var y = Num(20);
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// Define a rule to find any number and wrap it in 'Num(...)'
      t.FromTo("{@Number:n}", "Num({n})")
      
      Console.WriteLine(t.Transform("var x = 10.5; var y = 20;"))
   End Sub
End Module
				
			
var x = Num(10.5); var y = Num(20);
A simple example extracting the latter part of a sentence starting from a specific word.

ID: 1278

				
					using uCalcSoftware;

var uc = new uCalc();
using (var s = new uCalc.String("This is just a test")) {
   
   // Returns a view from 'just' to the end
   var result = s.StartingFrom("just");

   Console.WriteLine(result);
}
				
			
just a test
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::String s("This is just a test");
      s.Owned(); // Causes s to be released when it goes out of scope

      // Returns a view from 'just' to the end
      auto result = s.StartingFrom("just");

      cout << result << endl;
   }
}
				
			
just a test
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using s As New uCalc.String("This is just a test")
         
         '// Returns a view from 'just' to the end
         Dim result = s.StartingFrom("just")
         
         Console.WriteLine(result)
      End Using
   End Sub
End Module
				
			
just a test
A simple example showing how to extract a value from a nested configuration block.

ID: 939

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "Config { setting = 123; }";

// 1. Define the parent rule to capture the content inside the braces.
var parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false);

// 2. Get the local transformer for the parent rule.
var local_t = parentRule.LocalTransformer;

// 3. Define a rule that operates ONLY on the text captured by '{body}'.
local_t.FromTo("setting = {val}", "Found Value: {val}");

// 4. Perform the transformation.
// The local rule will run on the text " setting = 123; ".
t.Transform();

Console.WriteLine(t.Text);
				
			
Config { Found Value: 123; }
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("Config { setting = 123; }");

   // 1. Define the parent rule to capture the content inside the braces.
   auto parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false);

   // 2. Get the local transformer for the parent rule.
   auto local_t = parentRule.LocalTransformer();

   // 3. Define a rule that operates ONLY on the text captured by '{body}'.
   local_t.FromTo("setting = {val}", "Found Value: {val}");

   // 4. Perform the transformation.
   // The local rule will run on the text " setting = 123; ".
   t.Transform();

   cout << t.Text() << endl;
}
				
			
Config { Found Value: 123; }
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "Config { setting = 123; }"
      
      '// 1. Define the parent rule to capture the content inside the braces.
      Dim parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false)
      
      '// 2. Get the local transformer for the parent rule.
      Dim local_t = parentRule.LocalTransformer
      
      '// 3. Define a rule that operates ONLY on the text captured by '{body}'.
      local_t.FromTo("setting = {val}", "Found Value: {val}")
      
      '// 4. Perform the transformation.
      '// The local rule will run on the text " setting = 123; ".
      t.Transform()
      
      Console.WriteLine(t.Text)
   End Sub
End Module
				
			
Config { Found Value: 123; }
A simple find-and-replace operation using the fluent, chainable API.

ID: 1257

				
					using uCalcSoftware;

var uc = new uCalc();
using (var s = new uCalc.String("The quick brown fox.")) {
   
   // Replace returns the modified String object, but also modifies it in-place
   s.Replace("brown", "red");

   // Use implicit conversion to print the result
   Console.WriteLine(s);
};
				
			
The quick red fox.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::String s("The quick brown fox.");
      s.Owned(); // Causes s to be released when it goes out of scope

      // Replace returns the modified String object, but also modifies it in-place
      s.Replace("brown", "red");

      // Use implicit conversion to print the result
      cout << s << endl;
   };
}
				
			
The quick red fox.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using s As New uCalc.String("The quick brown fox.")
         
         '// Replace returns the modified String object, but also modifies it in-place
         s.Replace("brown", "red")
         
         '// Use implicit conversion to print the result
         Console.WriteLine(s)
      End Using
   End Sub
End Module
				
			
The quick red fox.
A simple find-and-replace operation using the fluent, chainable API.

ID: 1156

				
					using uCalcSoftware;

var uc = new uCalc();
using (var s = new uCalc.String("The quick brown fox.")) {
   
   // Replace returns the modified String object
   s.Replace("brown", "red");

   // Use implicit conversion to print the result
   Console.WriteLine(s);
}
				
			
The quick red fox.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::String s("The quick brown fox.");
      s.Owned(); // Causes s to be released when it goes out of scope

      // Replace returns the modified String object
      s.Replace("brown", "red");

      // Use implicit conversion to print the result
      cout << s << endl;
   }
}
				
			
The quick red fox.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using s As New uCalc.String("The quick brown fox.")
         
         '// Replace returns the modified String object
         s.Replace("brown", "red")
         
         '// Use implicit conversion to print the result
         Console.WriteLine(s)
      End Using
   End Sub
End Module
				
			
The quick red fox.
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
				
					#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;
}
				
			
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
				
			
25.4
A simple find-and-replace transformation to replace all occurrences of a word.

ID: 1141

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// Define a simple replacement rule
t.FromTo("Hello", "Greetings");

// Execute the transformation on an input string
t.Text = "Hello World, and Hello again.";
Console.WriteLine(t.Transform());
				
			
Greetings World, and Greetings again.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // Define a simple replacement rule
   t.FromTo("Hello", "Greetings");

   // Execute the transformation on an input string
   t.Text("Hello World, and Hello again.");
   cout << t.Transform() << endl;
}
				
			
Greetings World, and Greetings again.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// Define a simple replacement rule
      t.FromTo("Hello", "Greetings")
      
      '// Execute the transformation on an input string
      t.Text = "Hello World, and Hello again."
      Console.WriteLine(t.Transform())
   End Sub
End Module
				
			
Greetings World, and Greetings again.