uCalc SDK Interactive Examples

Extracting the status code and response time from a single log line using a simple pattern.

ID: 1388

				
					using uCalcSoftware;

var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
   string logLine = """
2024-10-26 10:00:05 INFO 192.168.1.10 "GET /api/users HTTP/1.1" 200 15ms
""";

   // Define a pattern to capture the status and time
   string pattern = "{@String:request} {@Number:status} {@Number:time}ms";

   // The replacement string formats the captured data for display
   // {request} or {request(1)} would return the string without surrounding quotes
   // {request(0)} returns the string with surrounding quotes
   string replacement = "Request: {request(0)}, Status: {status}, Time: {time}ms";

   t.FromTo(pattern, replacement);

   // Use Filter() to extract only the transformed match
   Console.WriteLine(t.Transform(logLine).Matches);
}
				
			
Request: "GET /api/users HTTP/1.1", Status: 200, Time: 15ms
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::Transformer t;
      t.Owned(); // Causes t to be released when it goes out of scope
      string logLine = R"(2024-10-26 10:00:05 INFO 192.168.1.10 "GET /api/users HTTP/1.1" 200 15ms)";

      // Define a pattern to capture the status and time
      string pattern = "{@String:request} {@Number:status} {@Number:time}ms";

      // The replacement string formats the captured data for display
      // {request} or {request(1)} would return the string without surrounding quotes
      // {request(0)} returns the string with surrounding quotes
      string replacement = "Request: {request(0)}, Status: {status}, Time: {time}ms";

      t.FromTo(pattern, replacement);

      // Use Filter() to extract only the transformed match
      cout << t.Transform(logLine).Matches() << endl;
   }
}
				
			
Request: "GET /api/users HTTP/1.1", Status: 200, Time: 15ms
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using t As New uCalc.Transformer()
         Dim logLine As String = "2024-10-26 10:00:05 INFO 192.168.1.10 ""GET /api/users HTTP/1.1"" 200 15ms"
         
         '// Define a pattern to capture the status and time
         Dim pattern As String = "{@String:request} {@Number:status} {@Number:time}ms"
         
         '// The replacement string formats the captured data for display
         '// {request} or {request(1)} would return the string without surrounding quotes
         '// {request(0)} returns the string with surrounding quotes
         Dim replacement As String = "Request: {request(0)}, Status: {status}, Time: {time}ms"
         
         t.FromTo(pattern, replacement)
         
         '// Use Filter() to extract only the transformed match
         Console.WriteLine(t.Transform(logLine).Matches)
      End Using
   End Sub
End Module
				
			
Request: "GET /api/users HTTP/1.1", Status: 200, Time: 15ms
Extracts a value from a simple key-value pair.

ID: 1198

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("ID: {value}", "Found value: {value}");
Console.WriteLine(t.Transform("Product ID: 12345"));
				
			
Product Found value: 12345
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.FromTo("ID: {value}", "Found value: {value}");
   cout << t.Transform("Product ID: 12345") << endl;
}
				
			
Product Found value: 12345
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.FromTo("ID: {value}", "Found value: {value}")
      Console.WriteLine(t.Transform("Product ID: 12345"))
   End Sub
End Module
				
			
Product Found value: 12345
Extracts all log entries from the second 'ERROR' onwards, demonstrating how the `occurrence` parameter skips initial matches.

ID: 1279

				
					using uCalcSoftware;

var uc = new uCalc();
using (var log = new uCalc.String("INFO: OK. ERROR: Fail 1. INFO: OK. ERROR: Fail 2.")) {
   
   // Find the second occurrence of "ERROR" and get everything after it.
   var remainingLog = log.StartingFrom("ERROR", 2);

   Console.WriteLine(remainingLog);
}
				
			
ERROR: Fail 2.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::String log("INFO: OK. ERROR: Fail 1. INFO: OK. ERROR: Fail 2.");
      log.Owned(); // Causes log to be released when it goes out of scope

      // Find the second occurrence of "ERROR" and get everything after it.
      auto remainingLog = log.StartingFrom("ERROR", 2);

      cout << remainingLog << endl;
   }
}
				
			
ERROR: Fail 2.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using log As New uCalc.String("INFO: OK. ERROR: Fail 1. INFO: OK. ERROR: Fail 2.")
         
         '// Find the second occurrence of "ERROR" and get everything after it.
         Dim remainingLog = log.StartingFrom("ERROR", 2)
         
         Console.WriteLine(remainingLog)
      End Using
   End Sub
End Module
				
			
ERROR: Fail 2.
Extracts all numbers from a string, demonstrating the simplicity of the `{@Number}` category matcher.

ID: 1338

				
					using uCalcSoftware;

var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
   t.FromTo("{@Number:n}", "[NUM:{n}]");

   var text = "Order 123 has 2 items for 49.95 total.";
   Console.WriteLine(t.Transform(text));
};
				
			
Order [NUM:123] has [NUM:2] items for [NUM:49.95] total.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::Transformer t;
      t.Owned(); // Causes t to be released when it goes out of scope
      t.FromTo("{@Number:n}", "[NUM:{n}]");

      auto text = "Order 123 has 2 items for 49.95 total.";
      cout << t.Transform(text) << endl;
   };
}
				
			
Order [NUM:123] has [NUM:2] items for [NUM:49.95] total.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using t As New uCalc.Transformer()
         t.FromTo("{@Number:n}", "[NUM:{n}]")
         
         Dim text = "Order 123 has 2 items for 49.95 total."
         Console.WriteLine(t.Transform(text))
      End Using
   End Sub
End Module
				
			
Order [NUM:123] has [NUM:2] items for [NUM:49.95] total.
Extracts the key from a simple key-value pair.

ID: 1269

See: Before
				
					using uCalcSoftware;

var uc = new uCalc();
using (var s = new uCalc.String("user:admin")) {
   var key = s.Before(":");
   Console.WriteLine(key);
}
				
			
user
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::String s("user:admin");
      s.Owned(); // Causes s to be released when it goes out of scope
      auto key = s.Before(":");
      cout << key << endl;
   }
}
				
			
user
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using s As New uCalc.String("user:admin")
         Dim key = s.Before(":")
         Console.WriteLine(key)
      End Using
   End Sub
End Module
				
			
user
Filters matches by rule; FilterByRule, Matches.Str, Matches.Count

ID: 855

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

var AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>");
var BoldTag = t.Pattern("<b>{text}</b>");
var H3Tag = t.Pattern("<h3>{text}</h3>");
t.Find();

Console.WriteLine($"All matches -- count = {t.Matches.Count()}");
Console.WriteLine("----------------------");
Console.WriteLine(t.Matches.Text);
Console.WriteLine("");

Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}");
Console.WriteLine("-------------------------------");
Console.WriteLine(BoldTag.Matches.Text);
Console.WriteLine("");

Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}");
Console.WriteLine("-----------------------------");
Console.WriteLine(H3Tag.Matches.Text);
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

   auto AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>");
   auto BoldTag = t.Pattern("<b>{text}</b>");
   auto H3Tag = t.Pattern("<h3>{text}</h3>");
   t.Find();

   cout << "All matches -- count = " << t.Matches().Count() << endl;
   cout << "----------------------" << endl;
   cout << t.Matches().Text() << endl;
   cout << "" << endl;

   cout << "Only BoldTag matches -- count = " << BoldTag.Matches().Count() << endl;
   cout << "-------------------------------" << endl;
   cout << BoldTag.Matches().Text() << endl;
   cout << "" << endl;

   cout << "Only H3Tag matches -- count = " << H3Tag.Matches().Count() << endl;
   cout << "-----------------------------" << endl;
   cout << H3Tag.Matches().Text() << endl;
}
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>")
      
      Dim AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>")
      Dim BoldTag = t.Pattern("<b>{text}</b>")
      Dim H3Tag = t.Pattern("<h3>{text}</h3>")
      t.Find()
      
      Console.WriteLine($"All matches -- count = {t.Matches.Count()}")
      Console.WriteLine("----------------------")
      Console.WriteLine(t.Matches.Text)
      Console.WriteLine("")
      
      Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}")
      Console.WriteLine("-------------------------------")
      Console.WriteLine(BoldTag.Matches.Text)
      Console.WriteLine("")
      
      Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}")
      Console.WriteLine("-----------------------------")
      Console.WriteLine(H3Tag.Matches.Text)
   End Sub
End Module
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
Filters matches by rule; FilterByRule, Matches.Str, Matches.Count

ID: 112

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

var AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>");
var BoldTag = t.Pattern("<b>{text}</b>");
var H3Tag = t.Pattern("<h3>{text}</h3>");
t.Find();

Console.WriteLine($"All matches -- count = {t.Matches.Count()}");
Console.WriteLine("----------------------");
Console.WriteLine(t.Matches);
Console.WriteLine("");

Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}");
Console.WriteLine("-------------------------------");
Console.WriteLine(BoldTag.Matches);
Console.WriteLine("");

Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}");
Console.WriteLine("-----------------------------");
Console.WriteLine(H3Tag.Matches);
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

   auto AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>");
   auto BoldTag = t.Pattern("<b>{text}</b>");
   auto H3Tag = t.Pattern("<h3>{text}</h3>");
   t.Find();

   cout << "All matches -- count = " << t.Matches().Count() << endl;
   cout << "----------------------" << endl;
   cout << t.Matches() << endl;
   cout << "" << endl;

   cout << "Only BoldTag matches -- count = " << BoldTag.Matches().Count() << endl;
   cout << "-------------------------------" << endl;
   cout << BoldTag.Matches() << endl;
   cout << "" << endl;

   cout << "Only H3Tag matches -- count = " << H3Tag.Matches().Count() << endl;
   cout << "-----------------------------" << endl;
   cout << H3Tag.Matches() << endl;
}
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>")
      
      Dim AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>")
      Dim BoldTag = t.Pattern("<b>{text}</b>")
      Dim H3Tag = t.Pattern("<h3>{text}</h3>")
      t.Find()
      
      Console.WriteLine($"All matches -- count = {t.Matches.Count()}")
      Console.WriteLine("----------------------")
      Console.WriteLine(t.Matches)
      Console.WriteLine("")
      
      Console.WriteLine($"Only BoldTag matches -- count = {BoldTag.Matches.Count()}")
      Console.WriteLine("-------------------------------")
      Console.WriteLine(BoldTag.Matches)
      Console.WriteLine("")
      
      Console.WriteLine($"Only H3Tag matches -- count = {H3Tag.Matches.Count()}")
      Console.WriteLine("-----------------------------")
      Console.WriteLine(H3Tag.Matches)
   End Sub
End Module
				
			
All matches -- count = 5
----------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
<p>My paragraph</p>

Only BoldTag matches -- count = 2
-------------------------------
<b>Bold statement</b>
<b>Other text</b>

Only H3Tag matches -- count = 2
-----------------------------
<h3>Title</h3>
<h3>Title B</h3>
Finding all occurrences of a letter except for the first one.

ID: 985

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "a b c a d e a f g";
var ruleA = t.FromTo("a", "[MATCH]");

// Skip the first 'a' that is found
ruleA.StartAfter = 1;

Console.WriteLine(t.Transform());
				
			
a b c [MATCH] d e [MATCH] f g
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.Text("a b c a d e a f g");
   auto ruleA = t.FromTo("a", "[MATCH]");

   // Skip the first 'a' that is found
   ruleA.StartAfter(1);

   cout << t.Transform() << endl;
}
				
			
a b c [MATCH] d e [MATCH] f g
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.Text = "a b c a d e a f g"
      Dim ruleA = t.FromTo("a", "[MATCH]")
      
      '// Skip the first 'a' that is found
      ruleA.StartAfter = 1
      
      Console.WriteLine(t.Transform())
   End Sub
End Module
				
			
a b c [MATCH] d e [MATCH] f g
Finding all occurrences of a specific word.

ID: 1065

See: Find
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "apple banana apple cherry apple";
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");
   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"
      t.Pattern("apple")
      t.Find()
      Console.WriteLine($"Found {t.Matches.Count()} occurrences of 'apple'.")
   End Sub
End Module
				
			
Found 3 occurrences of 'apple'.
Finding all occurrences of a word, getting the total count, and displaying the text of the first match.

ID: 1312

				
					using uCalcSoftware;

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

   var m = t.Matches;
   Console.WriteLine($"Matches found: {m.Count()}");
   if (m.Count() > 0) {
      Console.WriteLine($"First match: {m[0].Text}");
   }
};
				
			
Matches found: 2
First match: apple
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::Transformer t;
      t.Owned(); // Causes t to be released when it goes out of scope
      t.Text("apple banana apple cherry");
      t.Pattern("apple");
      t.Find();

      auto m = t.Matches();
      cout << "Matches found: " << m.Count() << endl;
      if (m.Count() > 0) {
         cout << "First match: " << m[0].Text() << endl;
      }
   };
}
				
			
Matches found: 2
First match: apple
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Using t As New uCalc.Transformer()
         t.Text = "apple banana apple cherry"
         t.Pattern("apple")
         t.Find()
         
         Dim m = t.Matches
         Console.WriteLine($"Matches found: {m.Count()}")
         If m.Count() > 0 Then
            Console.WriteLine($"First match: {m(0).Text}")
         End If
      End Using
   End Sub
End Module
				
			
Matches found: 2
First match: apple
Finding instances where there are two or more consecutive whitespace tokens and reducing them to a single space.

ID: 252

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
// Match two whitespace tokens and replace with one space
t.FromTo("{@Whitespace}", " ");

string messy = "var    x   =  100;";
Console.WriteLine(t.Transform(messy));
				
			
var x = 100;
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   // Match two whitespace tokens and replace with one space
   t.FromTo("{@Whitespace}", " ");

   string messy = "var    x   =  100;";
   cout << t.Transform(messy) << endl;
}
				
			
var x = 100;
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      '// Match two whitespace tokens and replace with one space
      t.FromTo("{@Whitespace}", " ")
      
      Dim messy As String = "var    x   =  100;"
      Console.WriteLine(t.Transform(messy))
   End Sub
End Module
				
			
var x = 100;
Finding the precedence level of an operator

ID: 24

				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineOperator("{a As Bool} ## {b As Bool} As Bool = a And b", uc.ItemOf("And").Precedence);
Console.WriteLine(uc.EvalStr("true Or false ## 2 > 5"));

uc.ItemOf("##").SetPrecedence(uc.ItemOf("Or").Precedence);
Console.WriteLine(uc.EvalStr("true Or false ## 2 > 5"));
				
			
true
false
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineOperator("{a As Bool} ## {b As Bool} As Bool = a And b", uc.ItemOf("And").Precedence());
   cout << uc.EvalStr("true Or false ## 2 > 5") << endl;

   uc.ItemOf("##").SetPrecedence(uc.ItemOf("Or").Precedence());
   cout << uc.EvalStr("true Or false ## 2 > 5") << endl;
}
				
			
true
false
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineOperator("{a As Bool} ## {b As Bool} As Bool = a And b", uc.ItemOf("And").Precedence)
      Console.WriteLine(uc.EvalStr("true Or false ## 2 > 5"))
      
      uc.ItemOf("##").SetPrecedence(uc.ItemOf("Or").Precedence)
      Console.WriteLine(uc.EvalStr("true Or false ## 2 > 5"))
   End Sub
End Module
				
			
true
false
Finds a single match and retrieves the name of the rule that generated it.

ID: 826

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var ruleA = t.FromTo("apple", "fruit");
t.Text = "an apple a day";
t.Find();

var firstMatch = t.Matches[0];
var generatingRule = firstMatch.Rule;

Console.Write("Match text: '"); Console.Write(firstMatch.Text); Console.Write("' was found by rule: '"); Console.Write(generatingRule.Name); Console.Write("'");
				
			
Match text: 'apple' was found by rule: 'apple'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto ruleA = t.FromTo("apple", "fruit");
   t.Text("an apple a day");
   t.Find();

   auto firstMatch = t.Matches()[0];
   auto generatingRule = firstMatch.Rule();

   cout << "Match text: '" << firstMatch.Text() << "' was found by rule: '" << generatingRule.Name() << "'";
}
				
			
Match text: 'apple' was found by rule: 'apple'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim ruleA = t.FromTo("apple", "fruit")
      t.Text = "an apple a day"
      t.Find()
      
      Dim firstMatch = t.Matches(0)
      Dim generatingRule = firstMatch.Rule
      
      Console.Write("Match text: '")
      Console.Write(firstMatch.Text)
      Console.Write("' was found by rule: '")
      Console.Write(generatingRule.Name)
      Console.Write("'")
   End Sub
End Module
				
			
Match text: 'apple' was found by rule: 'apple'
Finds and transforms only the first three occurrences of a pattern, ignoring any subsequent ones.

ID: 991

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "a b c a d e a f g a h i";
var ruleA = t.FromTo("a", "[A]");

// Only find and transform the first 3 occurrences of 'a'.
ruleA.StopAfter = 3;

Console.WriteLine(t.Transform());
				
			
[A] b c [A] d e [A] f g a h i
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("a b c a d e a f g a h i");
   auto ruleA = t.FromTo("a", "[A]");

   // Only find and transform the first 3 occurrences of 'a'.
   ruleA.StopAfter(3);

   cout << t.Transform() << endl;
}
				
			
[A] b c [A] d e [A] f g a h i
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "a b c a d e a f g a h i"
      Dim ruleA = t.FromTo("a", "[A]")
      
      '// Only find and transform the first 3 occurrences of 'a'.
      ruleA.StopAfter = 3
      
      Console.WriteLine(t.Transform())
   End Sub
End Module
				
			
[A] b c [A] d e [A] f g a h i
Finds the global index of a match that was retrieved from a rule-specific match list.

ID: 844

See: IndexOf
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";


var infoRule = t.Pattern("INFO: {msg}.");
var errorRule = t.Pattern("ERROR: {msg}.");
t.Text = log;
t.Find();

// Get the first match specific to the error rule
var firstErrorMatch = errorRule.Matches[0];
Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'");

// Now, find its index within the global list of all matches
var globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition);
Console.WriteLine($"The first error is the match at global index: {globalIndex}");

// Verify by printing the match from the global list
Console.WriteLine($"Global match at that index: '{t.Matches[globalIndex].Text}'");
				
			
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.'
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished.";


   auto infoRule = t.Pattern("INFO: {msg}.");
   auto errorRule = t.Pattern("ERROR: {msg}.");
   t.Text(log);
   t.Find();

   // Get the first match specific to the error rule
   auto firstErrorMatch = errorRule.Matches()[0];
   cout << "First error match text: '" << firstErrorMatch.Text() << "'" << endl;

   // Now, find its index within the global list of all matches
   auto globalIndex = t.Matches().IndexOf(firstErrorMatch.StartPosition());
   cout << "The first error is the match at global index: " << globalIndex << endl;

   // Verify by printing the match from the global list
   cout << "Global match at that index: '" << t.Matches()[globalIndex].Text() << "'" << endl;
}
				
			
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.'
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim log = "INFO: Task started. ERROR: Connection failed. INFO: Task finished."
      
      
      Dim infoRule = t.Pattern("INFO: {msg}.")
      Dim errorRule = t.Pattern("ERROR: {msg}.")
      t.Text = log
      t.Find()
      
      '// Get the first match specific to the error rule
      Dim firstErrorMatch = errorRule.Matches(0)
      Console.WriteLine($"First error match text: '{firstErrorMatch.Text}'")
      
      '// Now, find its index within the global list of all matches
      Dim globalIndex = t.Matches.IndexOf(firstErrorMatch.StartPosition)
      Console.WriteLine($"The first error is the match at global index: {globalIndex}")
      
      '// Verify by printing the match from the global list
      Console.WriteLine($"Global match at that index: '{t.Matches(globalIndex).Text}'")
   End Sub
End Module
				
			
First error match text: 'ERROR: Connection failed.'
The first error is the match at global index: 1
Global match at that index: 'ERROR: Connection failed.'
Focusable to select only patterns from local transformer

ID: 139

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var FruitsXML =
"""

<Fruits>
  <Fruit CommonName='Apple' ScientificName='Malus domestica' />
  <Fruit CommonName='Banana' ScientificName='Musa acuminata' />
  <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' />
  <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> -->
  <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' />
  <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' />
  <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> -->
  <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' />
  <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> -->
  <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' />
  <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' />
  <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> -->
</Fruits>

""";

// List names of fruit within comment, not the whole comment as well
t.Text = FruitsXML;
var CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false);
var CommentedFruitsTr = CommentedFruits.LocalTransformer;
CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true;

t.Filter();
Console.WriteLine("With Focusable()");
Console.WriteLine("----------------");
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");

// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
Console.WriteLine("Without Focusable()");
Console.WriteLine("-------------------");
Console.WriteLine(t.Matches.Text);
				
			
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon

Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto FruitsXML =
   R"(
<Fruits>
  <Fruit CommonName='Apple' ScientificName='Malus domestica' />
  <Fruit CommonName='Banana' ScientificName='Musa acuminata' />
  <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' />
  <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> -->
  <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' />
  <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' />
  <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> -->
  <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' />
  <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> -->
  <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' />
  <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' />
  <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> -->
</Fruits>
)";

   // List names of fruit within comment, not the whole comment as well
   t.Text(FruitsXML);
   auto CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false);
   auto CommentedFruitsTr = CommentedFruits.LocalTransformer();
   CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable(true);

   t.Filter();
   cout << "With Focusable()" << endl;
   cout << "----------------" << endl;
   cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
   cout << "" << endl;

   // Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
   cout << "Without Focusable()" << endl;
   cout << "-------------------" << endl;
   cout << t.Matches().Text() << endl;
}
				
			
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon

Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim FruitsXML =
      "
<Fruits>
  <Fruit CommonName='Apple' ScientificName='Malus domestica' />
  <Fruit CommonName='Banana' ScientificName='Musa acuminata' />
  <Fruit CommonName='Orange' ScientificName='Citrus × sinensis' />
  <!-- <Fruit CommonName='Grapes' ScientificName='Vitis vinifera' /> -->
  <Fruit CommonName='Strawberry' ScientificName='Fragaria × ananassa' />
  <Fruit CommonName='Pineapple' ScientificName='Ananas comosus' />
  <!-- <Fruit CommonName='Mango' ScientificName='Mangifera indica' /> -->
  <Fruit CommonName='Blueberry' ScientificName='Vaccinium corymbosum' />
  <!-- <Fruit CommonName='Rambutan' ScientificName='Nephelium lappaceum' /> -->
  <Fruit CommonName='Salak (Snake Fruit)' ScientificName='Salacca zalacca' />
  <Fruit CommonName='Jabuticaba' ScientificName='Plinia cauliflora' />
  <!-- <Fruit CommonName='Watermelon' ScientificName='Citrullus lanatus' /> -->
</Fruits>
"
      
      '// List names of fruit within comment, not the whole comment as well
      t.Text = FruitsXML
      Dim CommentedFruits = t.Pattern("<!-- {comment} -->").SetFocusable(false)
      Dim CommentedFruitsTr = CommentedFruits.LocalTransformer
      CommentedFruitsTr.FromTo("CommonName={@string:text}", "{text}").Focusable = true
      
      t.Filter()
      Console.WriteLine("With Focusable()")
      Console.WriteLine("----------------")
      Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
      Console.WriteLine("")
      
      '// Note: The displayed Fruit element is modified by CommentedFruitsTr.FromTo()
      Console.WriteLine("Without Focusable()")
      Console.WriteLine("-------------------")
      Console.WriteLine(t.Matches.Text)
   End Sub
End Module
				
			
With Focusable()
----------------
Grapes
Mango
Rambutan
Watermelon

Without Focusable()
-------------------
<!-- <Fruit Grapes ScientificName='Vitis vinifera' /> -->
Grapes
<!-- <Fruit Mango ScientificName='Mangifera indica' /> -->
Mango
<!-- <Fruit Rambutan ScientificName='Nephelium lappaceum' /> -->
Rambutan
<!-- <Fruit Watermelon ScientificName='Citrullus lanatus' /> -->
Watermelon
Focusable to toggle pattern matches

ID: 123

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>");

var BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true);
var H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true);
t.Find();

Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");

BoldTag.Focusable = false;
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}");
Console.WriteLine("--------------------------");
// t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");

BoldTag.Focusable = true;
Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}");
Console.WriteLine("--------------------------");

//t.Find(); // A Find operation does not have to be executed again
Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text);
Console.WriteLine("");
				
			
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>

BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>

BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

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

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>");

   auto BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true);
   auto H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true);
   t.Find();

   cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
   cout << "" << endl;

   BoldTag.Focusable(false);
   cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl;
   cout << "--------------------------" << endl;
   // t.Find(); // A Find operation does not have to be executed again
   cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
   cout << "" << endl;

   BoldTag.Focusable(true);
   cout << "BoldTag.Focusable(): " << tf(BoldTag.Focusable()) << endl;
   cout << "--------------------------" << endl;

   //t.Find(); // A Find operation does not have to be executed again
   cout << t.GetMatches(MatchesOption::FocusableOnly).Text() << endl;
   cout << "" << endl;
}
				
			
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>

BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>

BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b>")
      
      Dim BoldTag = t.Pattern("<b>{text}</b>").SetFocusable(true)
      Dim H3Tag = t.Pattern("<h3>{text}</h3>").SetFocusable(true)
      t.Find()
      
      Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
      Console.WriteLine("")
      
      BoldTag.Focusable = false
      Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}")
      Console.WriteLine("--------------------------")
      '// t.Find(); // A Find operation does not have to be executed again
      Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
      Console.WriteLine("")
      
      BoldTag.Focusable = true
      Console.WriteLine($"BoldTag.Focusable(): {BoldTag.Focusable}")
      Console.WriteLine("--------------------------")
      
      '//t.Find(); // A Find operation does not have to be executed again
      Console.WriteLine(t.GetMatches(MatchesOption.FocusableOnly).Text)
      Console.WriteLine("")
   End Sub
End Module
				
			
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>

BoldTag.Focusable(): False
--------------------------
<h3>Title</h3>
<h3>Title B</h3>

BoldTag.Focusable(): True
--------------------------
<h3>Title</h3>
<b>Bold statement</b>
<h3>Title B</h3>
<b>Other text</b>
Format using callback functions

ID: 26

				
					using uCalcSoftware;

var uc = new uCalc();

static void OutputAnswerCB(uCalc.Callback cb) {
   cb.ReturnStr("Answer: " + cb.ArgStr(1));
}
static void OutputSymbolCB(uCalc.Callback cb) {
   cb.ReturnStr("==> " + cb.ArgStr(1));
}
static void OutputBoolCB(uCalc.Callback cb) {
   if (cb.ArgStr(1) == "false") {
      cb.ReturnStr("No");
   } else if (cb.ArgStr(1) == "true") {
      cb.ReturnStr("Yes");
   }
}


// This format inserts "Answer: " in front of every result
var OutputAnswer = uc.Format( OutputAnswerCB);
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine("---");

// This one inserts ==> in front of the result
// The previously defined "Answer: " output is still prepended as well
var OutputSymbol = uc.Format( OutputSymbolCB);
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine("---");

// Causes Boolean values to return Yes or No (instead of true or false)
var OutputBool = uc.Format( OutputBoolCB, "Bool");
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));
Console.WriteLine("---");

// The previously defined "==>" output is removed
OutputSymbol.Release();
Console.WriteLine(uc.EvalStr("10+20"));
Console.WriteLine(uc.EvalStr("'Hello '+'world'"));
Console.WriteLine(uc.EvalStr("5 > 10"));
Console.WriteLine(uc.EvalStr("5 < 10"));
				
			
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

void ucalc_call OutputAnswerCB(uCalcBase::Callback cb) {
   cb.ReturnStr("Answer: " + cb.ArgStr(1));
}
void ucalc_call OutputSymbolCB(uCalcBase::Callback cb) {
   cb.ReturnStr("==> " + cb.ArgStr(1));
}
void ucalc_call OutputBoolCB(uCalcBase::Callback cb) {
   if (cb.ArgStr(1) == "false") {
      cb.ReturnStr("No");
   } else if (cb.ArgStr(1) == "true") {
      cb.ReturnStr("Yes");
   }
}
int main() {
   uCalc uc;

   // This format inserts "Answer: " in front of every result
   auto OutputAnswer = uc.Format( OutputAnswerCB);
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << "---" << endl;

   // This one inserts ==> in front of the result
   // The previously defined "Answer: " output is still prepended as well
   auto OutputSymbol = uc.Format( OutputSymbolCB);
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << "---" << endl;

   // Causes Boolean values to return Yes or No (instead of true or false)
   auto OutputBool = uc.Format( OutputBoolCB, "Bool");
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;
   cout << "---" << endl;

   // The previously defined "==>" output is removed
   OutputSymbol.Release();
   cout << uc.EvalStr("10+20") << endl;
   cout << uc.EvalStr("'Hello '+'world'") << endl;
   cout << uc.EvalStr("5 > 10") << endl;
   cout << uc.EvalStr("5 < 10") << endl;
}
				
			
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes
				
					Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub OutputAnswerCB(ByVal cb As uCalc.Callback)
      cb.ReturnStr("Answer: " + cb.ArgStr(1))
   End Sub
   Public Sub OutputSymbolCB(ByVal cb As uCalc.Callback)
      cb.ReturnStr("==> " + cb.ArgStr(1))
   End Sub
   Public Sub OutputBoolCB(ByVal cb As uCalc.Callback)
      If cb.ArgStr(1) = "false" Then
         cb.ReturnStr("No")
         ElseIf cb.ArgStr(1) = "true" Then
         cb.ReturnStr("Yes")
      End If
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      
      '// This format inserts "Answer: " in front of every result
      Dim OutputAnswer = uc.Format(AddressOf OutputAnswerCB)
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine("---")
      
      '// This one inserts ==> in front of the result
      '// The previously defined "Answer: " output is still prepended as well
      Dim OutputSymbol = uc.Format(AddressOf OutputSymbolCB)
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine("---")
      
      '// Causes Boolean values to return Yes or No (instead of true or false)
      Dim OutputBool = uc.Format(AddressOf OutputBoolCB, "Bool")
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine(uc.EvalStr("5 < 10"))
      Console.WriteLine("---")
      
      '// The previously defined "==>" output is removed
      OutputSymbol.Release()
      Console.WriteLine(uc.EvalStr("10+20"))
      Console.WriteLine(uc.EvalStr("'Hello '+'world'"))
      Console.WriteLine(uc.EvalStr("5 > 10"))
      Console.WriteLine(uc.EvalStr("5 < 10"))
   End Sub
End Module
				
			
Answer: 30
Answer: Hello world
Answer: false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> false
---
Answer: ==> 30
Answer: ==> Hello world
Answer: ==> No
Answer: ==> Yes
---
Answer: 30
Answer: Hello world
Answer: No
Answer: Yes
GetMessage

ID: 802

See: GetMessage
				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine(uc.Error.GetMessage(ErrorCode.Syntax_Error));
Console.WriteLine(uc.Error.GetMessage(ErrorCode.FloatOverflow));
				
			
Syntax error
Floating point overflow
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << uc.Error().GetMessage(ErrorCode::Syntax_Error) << endl;
   cout << uc.Error().GetMessage(ErrorCode::FloatOverflow) << endl;
}
				
			
Syntax error
Floating point overflow
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine(uc.Error.GetMessage(ErrorCode.Syntax_Error))
      Console.WriteLine(uc.Error.GetMessage(ErrorCode.FloatOverflow))
   End Sub
End Module
				
			
Syntax error
Floating point overflow
Gets uCalc object associated with an expression

ID: 97

				
					using uCalcSoftware;

var uc = new uCalc();
var MyExpr = uc.Parse("5+4");

Console.WriteLine(MyExpr.Evaluate());

MyExpr.uCalc.Format("Result = 'Answer = ' + Result");

Console.WriteLine(MyExpr.EvaluateStr());
				
			
9
Answer = 9
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto MyExpr = uc.Parse("5+4");

   cout << MyExpr.Evaluate() << endl;

   MyExpr.uCalc().Format("Result = 'Answer = ' + Result");

   cout << MyExpr.EvaluateStr() << endl;
}
				
			
9
Answer = 9
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim MyExpr = uc.Parse("5+4")
      
      Console.WriteLine(MyExpr.Evaluate())
      
      MyExpr.uCalc.Format("Result = 'Answer = ' + Result")
      
      Console.WriteLine(MyExpr.EvaluateStr())
   End Sub
End Module
				
			
9
Answer = 9
Getting data type object with DataTypeOf

ID: 2

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"));

Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name);
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize);
				
			
255
65535
true
-1
int8u
4
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl;
   cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl;
   cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl;
   cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl;

   cout << uc.DataTypeOf(BuiltInType::Integer_8u).Name() << endl;
   cout << uc.DataTypeOf(BuiltInType::Integer_32).ByteSize() << endl;
}
				
			
255
65535
true
-1
int8u
4
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"))
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"))
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"))
      Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"))
      
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name)
      Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize)
   End Sub
End Module
				
			
255
65535
true
-1
int8u
4
Grouping alternatives to limit scope.

ID: 242

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
// Matches "File Open" or "File Close".
// Capture needs explicit naming.
t.FromTo("File {cmd: Open | Close }", "Command: {cmd}");

Console.WriteLine(t.Transform("File Open"));
Console.WriteLine(t.Transform("File Close"));
				
			
Command: Open
Command: Close
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   // Matches "File Open" or "File Close".
   // Capture needs explicit naming.
   t.FromTo("File {cmd: Open | Close }", "Command: {cmd}");

   cout << t.Transform("File Open") << endl;
   cout << t.Transform("File Close") << endl;
}
				
			
Command: Open
Command: Close
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      '// Matches "File Open" or "File Close". 
      '// Capture needs explicit naming.
      t.FromTo("File {cmd: Open | Close }", "Command: {cmd}")
      
      Console.WriteLine(t.Transform("File Open"))
      Console.WriteLine(t.Transform("File Close"))
   End Sub
End Module
				
			
Command: Open
Command: Close
Handling an optional trailing semicolon.

ID: 239

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("Statement: {val} [;]", "Found: {val}");

Console.WriteLine(t.Transform("Statement: x = 1;")); // Output: Found: x = 1
Console.WriteLine(t.Transform("Statement: y = 2"));  // Output: Found: y = 2
				
			
Found: x = 1
Found: y = 2
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.FromTo("Statement: {val} [;]", "Found: {val}");

   cout << t.Transform("Statement: x = 1;") << endl; // Output: Found: x = 1
   cout << t.Transform("Statement: y = 2") << endl;  // Output: Found: y = 2
}
				
			
Found: x = 1
Found: y = 2
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.FromTo("Statement: {val} [;]", "Found: {val}")
      
      Console.WriteLine(t.Transform("Statement: x = 1;")) '// Output: Found: x = 1
      Console.WriteLine(t.Transform("Statement: y = 2"))  '// Output: Found: y = 2
   End Sub
End Module
				
			
Found: x = 1
Found: y = 2
Handling Brackets and Literals.

ID: 247

See: Tokens
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
// Capture a function call.
// {@Alpha} matches the name.
// '(' and ')' are Bracket tokens that ensure the content is captured correctly.
t.FromTo("{@Alpha:func} ( {args} )", "Call: {func} with {args}");

Console.WriteLine(t.Transform("myfunc('Hello World', (x + y) * 2 )"));
				
			
Call: myfunc with 'Hello World', (x + y) * 2
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   // Capture a function call.
   // {@Alpha} matches the name.
   // '(' and ')' are Bracket tokens that ensure the content is captured correctly.
   t.FromTo("{@Alpha:func} ( {args} )", "Call: {func} with {args}");

   cout << t.Transform("myfunc('Hello World', (x + y) * 2 )") << endl;
}
				
			
Call: myfunc with 'Hello World', (x + y) * 2
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      '// Capture a function call. 
      '// {@Alpha} matches the name. 
      '// '(' and ')' are Bracket tokens that ensure the content is captured correctly.
      t.FromTo("{@Alpha:func} ( {args} )", "Call: {func} with {args}")
      
      Console.WriteLine(t.Transform("myfunc('Hello World', (x + y) * 2 )"))
   End Sub
End Module
				
			
Call: myfunc with 'Hello World', (x + y) * 2
How `SkipOver` creates 'dead zones' where other rules are not applied.

ID: 1123

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "transform this but (not this) and this";

// A rule to replace the word 'this'
t.FromTo("this", "THAT");

// A rule to ignore any content inside parentheses
t.SkipOver("({content})");

// The 'this' inside the parentheses is protected by the SkipOver rule
Console.WriteLine(t.Transform());
				
			
transform THAT but (not this) and THAT
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.Text("transform this but (not this) and this");

   // A rule to replace the word 'this'
   t.FromTo("this", "THAT");

   // A rule to ignore any content inside parentheses
   t.SkipOver("({content})");

   // The 'this' inside the parentheses is protected by the SkipOver rule
   cout << t.Transform() << endl;
}
				
			
transform THAT but (not this) and THAT
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.Text = "transform this but (not this) and this"
      
      '// A rule to replace the word 'this'
      t.FromTo("this", "THAT")
      
      '// A rule to ignore any content inside parentheses
      t.SkipOver("({content})")
      
      '// The 'this' inside the parentheses is protected by the SkipOver rule
      Console.WriteLine(t.Transform())
   End Sub
End Module
				
			
transform THAT but (not this) and THAT
How a rule fails if it doesn't meet the minimum match count.

ID: 948

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var ruleA = t.FromTo("a", "A");
ruleA.Minimum = 3;

Console.WriteLine("--- Case 1: Fails (only 2 'a's) ---");
t.Transform("a b a b c");
Console.WriteLine($"Result: {t}");
Console.WriteLine($"Matches Found: {t.Matches.Count()}");

Console.WriteLine("");
Console.WriteLine("--- Case 2: Succeeds (3 'a's) ---");
t.Transform("a b a b a c");
Console.WriteLine($"Result: {t}");
Console.WriteLine($"Matches Found: {t.Matches.Count()}");
				
			
--- Case 1: Fails (only 2 'a's) ---
Result: a b a b c
Matches Found: 0

--- Case 2: Succeeds (3 'a's) ---
Result: A b A b A c
Matches Found: 3
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto ruleA = t.FromTo("a", "A");
   ruleA.Minimum(3);

   cout << "--- Case 1: Fails (only 2 'a's) ---" << endl;
   t.Transform("a b a b c");
   cout << "Result: " << t << endl;
   cout << "Matches Found: " << t.Matches().Count() << endl;

   cout << "" << endl;
   cout << "--- Case 2: Succeeds (3 'a's) ---" << endl;
   t.Transform("a b a b a c");
   cout << "Result: " << t << endl;
   cout << "Matches Found: " << t.Matches().Count() << endl;
}
				
			
--- Case 1: Fails (only 2 'a's) ---
Result: a b a b c
Matches Found: 0

--- Case 2: Succeeds (3 'a's) ---
Result: A b A b A c
Matches Found: 3
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim ruleA = t.FromTo("a", "A")
      ruleA.Minimum = 3
      
      Console.WriteLine("--- Case 1: Fails (only 2 'a's) ---")
      t.Transform("a b a b c")
      Console.WriteLine($"Result: {t}")
      Console.WriteLine($"Matches Found: {t.Matches.Count()}")
      
      Console.WriteLine("")
      Console.WriteLine("--- Case 2: Succeeds (3 'a's) ---")
      t.Transform("a b a b a c")
      Console.WriteLine($"Result: {t}")
      Console.WriteLine($"Matches Found: {t.Matches.Count()}")
   End Sub
End Module
				
			
--- Case 1: Fails (only 2 'a's) ---
Result: a b a b c
Matches Found: 0

--- Case 2: Succeeds (3 'a's) ---
Result: A b A b A c
Matches Found: 3
How adding tokens affects their index and, therefore, their precedence.

ID: 1036

See: IndexOf
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
var tokens = t.Tokens;
tokens.Clear();
tokens.Add("."); // Add a fallback token at index 0

// The order of definition determines the index (precedence)
var tokenA = tokens.Add("A");
var tokenB = tokens.Add("B");

Console.WriteLine($"Index of A: {tokens.IndexOf(tokenA)}"); // Will have a lower index
Console.WriteLine($"Index of B: {tokens.IndexOf(tokenB)}"); // Will have a higher index, thus higher precedence
				
			
Index of A: 1
Index of B: 2
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   auto tokens = t.Tokens();
   tokens.Clear();
   tokens.Add("."); // Add a fallback token at index 0

   // The order of definition determines the index (precedence)
   auto tokenA = tokens.Add("A");
   auto tokenB = tokens.Add("B");

   cout << "Index of A: " << tokens.IndexOf(tokenA) << endl; // Will have a lower index
   cout << "Index of B: " << tokens.IndexOf(tokenB) << endl; // Will have a higher index, thus higher precedence
}
				
			
Index of A: 1
Index of B: 2
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      Dim tokens = t.Tokens
      tokens.Clear()
      tokens.Add(".") '// Add a fallback token at index 0
      
      '// The order of definition determines the index (precedence)
      Dim tokenA = tokens.Add("A")
      Dim tokenB = tokens.Add("B")
      
      Console.WriteLine($"Index of A: {tokens.IndexOf(tokenA)}") '// Will have a lower index
      Console.WriteLine($"Index of B: {tokens.IndexOf(tokenB)}") '// Will have a higher index, thus higher precedence
   End Sub
End Module
				
			
Index of A: 1
Index of B: 2
How to assign and retrieve descriptions for specific transformation patterns using SetDescription().

ID: 118

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

var AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>").SetDescription("other kind of tag");
var BoldTag = t.Pattern("<b>{text}</b>").SetDescription("bold tag");
var H3Tag = t.Pattern("<h3>{text}</h3>").SetDescription("h3 tag");
t.Find();

foreach(var match in t.Matches) {
   Console.WriteLine(match.Text + "   Description: " + match.Rule.Description);
}
				
			
<h3>Title</h3>   Description: h3 tag
<b>Bold statement</b>   Description: bold tag
<h3>Title B</h3>   Description: h3 tag
<b>Other text</b>   Description: bold tag
<p>My paragraph</p>   Description: other kind of tag
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>");

   auto AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>").SetDescription("other kind of tag");
   auto BoldTag = t.Pattern("<b>{text}</b>").SetDescription("bold tag");
   auto H3Tag = t.Pattern("<h3>{text}</h3>").SetDescription("h3 tag");
   t.Find();

   for(auto match : t.Matches()) {
      cout << match.Text() + "   Description: " + match.Rule().Description() << endl;
   }
}
				
			
<h3>Title</h3>   Description: h3 tag
<b>Bold statement</b>   Description: bold tag
<h3>Title B</h3>   Description: h3 tag
<b>Other text</b>   Description: bold tag
<p>My paragraph</p>   Description: other kind of tag
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Str("<h3>Title</h3><b>Bold statement</b><h3>Title B</h3><b>Other text</b><p>My paragraph</p>")
      
      Dim AnyOtherTag = t.Pattern("<{tag}>{text}</{tag}>").SetDescription("other kind of tag")
      Dim BoldTag = t.Pattern("<b>{text}</b>").SetDescription("bold tag")
      Dim H3Tag = t.Pattern("<h3>{text}</h3>").SetDescription("h3 tag")
      t.Find()
      
      For Each match In t.Matches
         Console.WriteLine(match.Text + "   Description: " + match.Rule.Description)
      Next
   End Sub
End Module
				
			
<h3>Title</h3>   Description: h3 tag
<b>Bold statement</b>   Description: bold tag
<h3>Title B</h3>   Description: h3 tag
<b>Other text</b>   Description: bold tag
<p>My paragraph</p>   Description: other kind of tag
How to count all alphanumeric words in a sentence.

ID: 785

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "There are five words here.";

// Define a pattern to find any alphanumeric word
t.Pattern("{@Alpha}");
t.Find();

Console.WriteLine($"Total words found: {t.Matches.Count()}");
				
			
Total words found: 5
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.Text("There are five words here.");

   // Define a pattern to find any alphanumeric word
   t.Pattern("{@Alpha}");
   t.Find();

   cout << "Total words found: " << t.Matches().Count() << endl;
}
				
			
Total words found: 5
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.Text = "There are five words here."
      
      '// Define a pattern to find any alphanumeric word
      t.Pattern("{@Alpha}")
      t.Find()
      
      Console.WriteLine($"Total words found: {t.Matches.Count()}")
   End Sub
End Module
				
			
Total words found: 5
How to define a constant, variable, operator, function, output format, and token with Define()

ID: 6

See: Define
				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine("------ Basic examples -------");
uc.Define("Function: f(x, y) = x + y");
uc.Define("Operator: {x} %% {y} = x * y");
uc.Define("Variable: MyVar = 123");

Console.WriteLine(uc.Eval("f(5, 10)"));
Console.WriteLine(uc.Eval("5 %% 10"));
Console.WriteLine(uc.Eval("MyVar * 100"));

// End users can also call Define()
Console.WriteLine("------ End user definition -------");
uc.Eval("Define('Function: ff(x) = x * 1000')");
Console.WriteLine(uc.Eval("ff(987)"));

Console.WriteLine("------ Boolean format -------");
Console.WriteLine(uc.EvalStr("1 < 2"));
Console.WriteLine(uc.EvalStr("1 > 2"));
Console.WriteLine(uc.EvalStr("Int(1 < 2)"));
Console.WriteLine(uc.EvalStr("(True Or False) And (True And False)"));
uc.Define("Boolean: 55, TotallyTrue, CompletelyFalse");
Console.WriteLine(uc.EvalStr("1 < 2"));
Console.WriteLine(uc.EvalStr("1 > 2"));
Console.WriteLine(uc.EvalStr("Int(1 < 2)"));
Console.WriteLine(uc.EvalStr("(TotallyTrue Or CompletelyFalse) And (TotallyTrue And CompletelyFalse)"));

// Format - configures the formatting for the output given by EvalStr
Console.WriteLine("------ Format -------");
uc.Define("Format: Result = 'Answer: <' + Result + '>'");
uc.Define("Format: String, val = 'String Value --> ' + val");
Console.WriteLine(uc.EvalStr("1+2"));
Console.WriteLine(uc.EvalStr("'Hello ' + 'world!'"));
var Additional = uc.Define("Format: ret = 'Additional format: ' + ret");
Console.WriteLine(uc.EvalStr("1+2"));
uc.Define("Format: InsertAt: 0, result = 'The ' + result");
Console.WriteLine(uc.EvalStr("1+2"));
Additional.Release();
Console.WriteLine(uc.EvalStr("1+2"));
uc.FormatRemove();

// Bootstrap - builds new def on top of existing one
Console.WriteLine("------ Bootstrap -------");
Console.WriteLine(uc.EvalStr("Hex(123)")); // uses "built-in" version of Hex()
var MyHex = uc.Define("Bootstrap ~~ Function: Hex(number As Int) As String = '0x' + UCase(Hex(number))");
Console.WriteLine(uc.EvalStr("Hex(123)"));
MyHex.Release();
Console.WriteLine(uc.EvalStr("Hex(123)"));

// Overwrite - useful for spreadsheet-like functionality
Console.WriteLine("------ Overwrite -------");
uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 5");
uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 10");
uc.Define("Overwrite ~~ Func: SpreadsheetCell_C3() = SpreadsheetCell_A1() + SpreadsheetCell_B2()");
Console.WriteLine(uc.Eval("SpreadsheetCell_A1()"));
Console.WriteLine(uc.Eval("SpreadsheetCell_B2()"));
Console.WriteLine(uc.Eval("SpreadsheetCell_C3()"));
// SpreadsheetCell_C3() will be affected by the definition changes of SpreadsheetCell_A1() and  SpreadsheetCell_B3()
uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 100");
uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 25");
Console.WriteLine("-------");
// Note: Empty parenthesis are optional for functions with no parameters
Console.WriteLine(uc.Eval("SpreadsheetCell_A1"));
Console.WriteLine(uc.Eval("SpreadsheetCell_B2"));
Console.WriteLine(uc.Eval("SpreadsheetCell_C3"));

// Lock
Console.WriteLine("------ Lock -------");
uc.Define("Variable: xy = 555");
uc.Define("Lock ~~ Variable: pi = 3.14"); // like using DefineConstant()
Console.WriteLine(uc.EvalStr("xy"));
Console.WriteLine(uc.EvalStr("pi"));
Console.WriteLine(uc.EvalStr("xy = 222")); // This variable is being changed
Console.WriteLine(uc.EvalStr("pi = 3.14159")); // This one is locked and cannot be changed
Console.WriteLine(uc.EvalStr("xy")); // Returns the new value of xy
Console.WriteLine(uc.EvalStr("pi")); // pi did not change; returns original value
Console.WriteLine("-------");
uc.Define("Function: f1(x) = x + 100");
uc.Define("Lock ~~ Function: f2(x) = x + 200"); // End-user can't change f2
Console.WriteLine(uc.Eval("f1(5)"));
Console.WriteLine(uc.Eval("f2(5)"));
uc.Eval("Define('Function: f1(x) = x + 300')");
uc.Eval("Define('Function: f2(x) = x + 400')"); // This re-definition is ignored
Console.WriteLine(uc.Eval("f1(5)"));
Console.WriteLine(uc.Eval("f2(5)"));

// Tokens
Console.WriteLine("------ Tokens -------");
Console.WriteLine(uc.EvalStr("5 + 4 // This comment causes an error"));
Console.WriteLine(uc.EvalStr("5 + /* comment not recognized yet */ 10"));
uc.Define("TokenType: Whitespace ~~ Token: //.*"); // // C-style to end-of-line comment
uc.Define("TokenType: Whitespace ~~ Token: /[*].*?[*]/"); // /* C-style enclosed comment */
Console.WriteLine(uc.EvalStr("5 + 4 // This comment will be ignored"));
Console.WriteLine(uc.EvalStr("5 + /* comment ignored */ 10"));

// Precedence
Console.WriteLine("------ Precedence -------");
uc.Define("Precedence: 1    ~~ Operator: {a As Int32} OpA {b As Int32} = a + b");
uc.Define("Precedence: 1000 ~~ Operator: {a As Int32} OpB {b As Int32} = a + b");
Console.WriteLine(uc.Eval("5 OpA 4 * 10"));
Console.WriteLine(uc.Eval("5 OpB 4 * 10"));

// Associativity
Console.WriteLine("------ Associativity -------");
uc.Define("Associativity: LeftToRight ~~ Operator: {x} OpX {y} = x / y");
uc.Define("Associativity: RightToLeft ~~ Operator: {x} OpY {y} = x / y");
Console.WriteLine(uc.Eval("3 OpX 4 OpX 5"));
Console.WriteLine(uc.Eval("3 OpY 4 OpY 5"));
				
			
------ Basic examples -------
15
50
12300
------ End user definition -------
987000
------ Boolean format -------
true
false
1
false
TotallyTrue
CompletelyFalse
55
CompletelyFalse
------ Format -------
Answer: <3>
Answer: <String Value --> Hello world!>
Answer: <Additional format: 3>
The Answer: <Additional format: 3>
The Answer: <3>
------ Bootstrap -------
7b
0x7B
7b
------ Overwrite -------
5
50
55
-------
25
2500
2525
------ Lock -------
555
3.14
222
Value cannot be assigned here
222
3.14
-------
105
205
305
205
------ Tokens -------
Undefined identifier
Undefined identifier
9
15
------ Precedence -------
45
90
------ Associativity -------
0.15
3.75
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << "------ Basic examples -------" << endl;
   uc.Define("Function: f(x, y) = x + y");
   uc.Define("Operator: {x} %% {y} = x * y");
   uc.Define("Variable: MyVar = 123");

   cout << uc.Eval("f(5, 10)") << endl;
   cout << uc.Eval("5 %% 10") << endl;
   cout << uc.Eval("MyVar * 100") << endl;

   // End users can also call Define()
   cout << "------ End user definition -------" << endl;
   uc.Eval("Define('Function: ff(x) = x * 1000')");
   cout << uc.Eval("ff(987)") << endl;

   cout << "------ Boolean format -------" << endl;
   cout << uc.EvalStr("1 < 2") << endl;
   cout << uc.EvalStr("1 > 2") << endl;
   cout << uc.EvalStr("Int(1 < 2)") << endl;
   cout << uc.EvalStr("(True Or False) And (True And False)") << endl;
   uc.Define("Boolean: 55, TotallyTrue, CompletelyFalse");
   cout << uc.EvalStr("1 < 2") << endl;
   cout << uc.EvalStr("1 > 2") << endl;
   cout << uc.EvalStr("Int(1 < 2)") << endl;
   cout << uc.EvalStr("(TotallyTrue Or CompletelyFalse) And (TotallyTrue And CompletelyFalse)") << endl;

   // Format - configures the formatting for the output given by EvalStr
   cout << "------ Format -------" << endl;
   uc.Define("Format: Result = 'Answer: <' + Result + '>'");
   uc.Define("Format: String, val = 'String Value --> ' + val");
   cout << uc.EvalStr("1+2") << endl;
   cout << uc.EvalStr("'Hello ' + 'world!'") << endl;
   auto Additional = uc.Define("Format: ret = 'Additional format: ' + ret");
   cout << uc.EvalStr("1+2") << endl;
   uc.Define("Format: InsertAt: 0, result = 'The ' + result");
   cout << uc.EvalStr("1+2") << endl;
   Additional.Release();
   cout << uc.EvalStr("1+2") << endl;
   uc.FormatRemove();

   // Bootstrap - builds new def on top of existing one
   cout << "------ Bootstrap -------" << endl;
   cout << uc.EvalStr("Hex(123)") << endl; // uses "built-in" version of Hex()
   auto MyHex = uc.Define("Bootstrap ~~ Function: Hex(number As Int) As String = '0x' + UCase(Hex(number))");
   cout << uc.EvalStr("Hex(123)") << endl;
   MyHex.Release();
   cout << uc.EvalStr("Hex(123)") << endl;

   // Overwrite - useful for spreadsheet-like functionality
   cout << "------ Overwrite -------" << endl;
   uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 5");
   uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 10");
   uc.Define("Overwrite ~~ Func: SpreadsheetCell_C3() = SpreadsheetCell_A1() + SpreadsheetCell_B2()");
   cout << uc.Eval("SpreadsheetCell_A1()") << endl;
   cout << uc.Eval("SpreadsheetCell_B2()") << endl;
   cout << uc.Eval("SpreadsheetCell_C3()") << endl;
   // SpreadsheetCell_C3() will be affected by the definition changes of SpreadsheetCell_A1() and  SpreadsheetCell_B3()
   uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 100");
   uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 25");
   cout << "-------" << endl;
   // Note: Empty parenthesis are optional for functions with no parameters
   cout << uc.Eval("SpreadsheetCell_A1") << endl;
   cout << uc.Eval("SpreadsheetCell_B2") << endl;
   cout << uc.Eval("SpreadsheetCell_C3") << endl;

   // Lock
   cout << "------ Lock -------" << endl;
   uc.Define("Variable: xy = 555");
   uc.Define("Lock ~~ Variable: pi = 3.14"); // like using DefineConstant()
   cout << uc.EvalStr("xy") << endl;
   cout << uc.EvalStr("pi") << endl;
   cout << uc.EvalStr("xy = 222") << endl; // This variable is being changed
   cout << uc.EvalStr("pi = 3.14159") << endl; // This one is locked and cannot be changed
   cout << uc.EvalStr("xy") << endl; // Returns the new value of xy
   cout << uc.EvalStr("pi") << endl; // pi did not change; returns original value
   cout << "-------" << endl;
   uc.Define("Function: f1(x) = x + 100");
   uc.Define("Lock ~~ Function: f2(x) = x + 200"); // End-user can't change f2
   cout << uc.Eval("f1(5)") << endl;
   cout << uc.Eval("f2(5)") << endl;
   uc.Eval("Define('Function: f1(x) = x + 300')");
   uc.Eval("Define('Function: f2(x) = x + 400')"); // This re-definition is ignored
   cout << uc.Eval("f1(5)") << endl;
   cout << uc.Eval("f2(5)") << endl;

   // Tokens
   cout << "------ Tokens -------" << endl;
   cout << uc.EvalStr("5 + 4 // This comment causes an error") << endl;
   cout << uc.EvalStr("5 + /* comment not recognized yet */ 10") << endl;
   uc.Define("TokenType: Whitespace ~~ Token: //.*"); // // C-style to end-of-line comment
   uc.Define("TokenType: Whitespace ~~ Token: /[*].*?[*]/"); // /* C-style enclosed comment */
   cout << uc.EvalStr("5 + 4 // This comment will be ignored") << endl;
   cout << uc.EvalStr("5 + /* comment ignored */ 10") << endl;

   // Precedence
   cout << "------ Precedence -------" << endl;
   uc.Define("Precedence: 1    ~~ Operator: {a As Int32} OpA {b As Int32} = a + b");
   uc.Define("Precedence: 1000 ~~ Operator: {a As Int32} OpB {b As Int32} = a + b");
   cout << uc.Eval("5 OpA 4 * 10") << endl;
   cout << uc.Eval("5 OpB 4 * 10") << endl;

   // Associativity
   cout << "------ Associativity -------" << endl;
   uc.Define("Associativity: LeftToRight ~~ Operator: {x} OpX {y} = x / y");
   uc.Define("Associativity: RightToLeft ~~ Operator: {x} OpY {y} = x / y");
   cout << uc.Eval("3 OpX 4 OpX 5") << endl;
   cout << uc.Eval("3 OpY 4 OpY 5") << endl;
}
				
			
------ Basic examples -------
15
50
12300
------ End user definition -------
987000
------ Boolean format -------
true
false
1
false
TotallyTrue
CompletelyFalse
55
CompletelyFalse
------ Format -------
Answer: <3>
Answer: <String Value --> Hello world!>
Answer: <Additional format: 3>
The Answer: <Additional format: 3>
The Answer: <3>
------ Bootstrap -------
7b
0x7B
7b
------ Overwrite -------
5
50
55
-------
25
2500
2525
------ Lock -------
555
3.14
222
Value cannot be assigned here
222
3.14
-------
105
205
305
205
------ Tokens -------
Undefined identifier
Undefined identifier
9
15
------ Precedence -------
45
90
------ Associativity -------
0.15
3.75
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine("------ Basic examples -------")
      uc.Define("Function: f(x, y) = x + y")
      uc.Define("Operator: {x} %% {y} = x * y")
      uc.Define("Variable: MyVar = 123")
      
      Console.WriteLine(uc.Eval("f(5, 10)"))
      Console.WriteLine(uc.Eval("5 %% 10"))
      Console.WriteLine(uc.Eval("MyVar * 100"))
      
      '// End users can also call Define()
      Console.WriteLine("------ End user definition -------")
      uc.Eval("Define('Function: ff(x) = x * 1000')")
      Console.WriteLine(uc.Eval("ff(987)"))
      
      Console.WriteLine("------ Boolean format -------")
      Console.WriteLine(uc.EvalStr("1 < 2"))
      Console.WriteLine(uc.EvalStr("1 > 2"))
      Console.WriteLine(uc.EvalStr("Int(1 < 2)"))
      Console.WriteLine(uc.EvalStr("(True Or False) And (True And False)"))
      uc.Define("Boolean: 55, TotallyTrue, CompletelyFalse")
      Console.WriteLine(uc.EvalStr("1 < 2"))
      Console.WriteLine(uc.EvalStr("1 > 2"))
      Console.WriteLine(uc.EvalStr("Int(1 < 2)"))
      Console.WriteLine(uc.EvalStr("(TotallyTrue Or CompletelyFalse) And (TotallyTrue And CompletelyFalse)"))
      
      '// Format - configures the formatting for the output given by EvalStr
      Console.WriteLine("------ Format -------")
      uc.Define("Format: Result = 'Answer: <' + Result + '>'")
      uc.Define("Format: String, val = 'String Value --> ' + val")
      Console.WriteLine(uc.EvalStr("1+2"))
      Console.WriteLine(uc.EvalStr("'Hello ' + 'world!'"))
      Dim Additional = uc.Define("Format: ret = 'Additional format: ' + ret")
      Console.WriteLine(uc.EvalStr("1+2"))
      uc.Define("Format: InsertAt: 0, result = 'The ' + result")
      Console.WriteLine(uc.EvalStr("1+2"))
      Additional.Release()
      Console.WriteLine(uc.EvalStr("1+2"))
      uc.FormatRemove()
      
      '// Bootstrap - builds new def on top of existing one
      Console.WriteLine("------ Bootstrap -------")
      Console.WriteLine(uc.EvalStr("Hex(123)")) '// uses "built-in" version of Hex()
      Dim MyHex = uc.Define("Bootstrap ~~ Function: Hex(number As Int) As String = '0x' + UCase(Hex(number))")
      Console.WriteLine(uc.EvalStr("Hex(123)"))
      MyHex.Release()
      Console.WriteLine(uc.EvalStr("Hex(123)"))
      
      '// Overwrite - useful for spreadsheet-like functionality
      Console.WriteLine("------ Overwrite -------")
      uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 5")
      uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 10")
      uc.Define("Overwrite ~~ Func: SpreadsheetCell_C3() = SpreadsheetCell_A1() + SpreadsheetCell_B2()")
      Console.WriteLine(uc.Eval("SpreadsheetCell_A1()"))
      Console.WriteLine(uc.Eval("SpreadsheetCell_B2()"))
      Console.WriteLine(uc.Eval("SpreadsheetCell_C3()"))
      '// SpreadsheetCell_C3() will be affected by the definition changes of SpreadsheetCell_A1() and  SpreadsheetCell_B3()
      uc.Define("Overwrite ~~ Func: SpreadsheetCell_B2() = SpreadsheetCell_A1() * 100")
      uc.Define("Overwrite ~~ Func: SpreadsheetCell_A1() = 25")
      Console.WriteLine("-------")
      '// Note: Empty parenthesis are optional for functions with no parameters
      Console.WriteLine(uc.Eval("SpreadsheetCell_A1"))
      Console.WriteLine(uc.Eval("SpreadsheetCell_B2"))
      Console.WriteLine(uc.Eval("SpreadsheetCell_C3"))
      
      '// Lock
      Console.WriteLine("------ Lock -------")
      uc.Define("Variable: xy = 555")
      uc.Define("Lock ~~ Variable: pi = 3.14") '// like using DefineConstant()
      Console.WriteLine(uc.EvalStr("xy"))
      Console.WriteLine(uc.EvalStr("pi"))
      Console.WriteLine(uc.EvalStr("xy = 222")) '// This variable is being changed
      Console.WriteLine(uc.EvalStr("pi = 3.14159")) '// This one is locked and cannot be changed
      Console.WriteLine(uc.EvalStr("xy")) '// Returns the new value of xy
      Console.WriteLine(uc.EvalStr("pi")) '// pi did not change; returns original value
      Console.WriteLine("-------")
      uc.Define("Function: f1(x) = x + 100")
      uc.Define("Lock ~~ Function: f2(x) = x + 200") '// End-user can't change f2
      Console.WriteLine(uc.Eval("f1(5)"))
      Console.WriteLine(uc.Eval("f2(5)"))
      uc.Eval("Define('Function: f1(x) = x + 300')")
      uc.Eval("Define('Function: f2(x) = x + 400')") '// This re-definition is ignored
      Console.WriteLine(uc.Eval("f1(5)"))
      Console.WriteLine(uc.Eval("f2(5)"))
      
      '// Tokens
      Console.WriteLine("------ Tokens -------")
      Console.WriteLine(uc.EvalStr("5 + 4 // This comment causes an error"))
      Console.WriteLine(uc.EvalStr("5 + /* comment not recognized yet */ 10"))
      uc.Define("TokenType: Whitespace ~~ Token: //.*") '// // C-style to end-of-line comment 
      uc.Define("TokenType: Whitespace ~~ Token: /[*].*?[*]/") '// /* C-style enclosed comment */
      Console.WriteLine(uc.EvalStr("5 + 4 // This comment will be ignored"))
      Console.WriteLine(uc.EvalStr("5 + /* comment ignored */ 10"))
      
      '// Precedence
      Console.WriteLine("------ Precedence -------")
      uc.Define("Precedence: 1    ~~ Operator: {a As Int32} OpA {b As Int32} = a + b")
      uc.Define("Precedence: 1000 ~~ Operator: {a As Int32} OpB {b As Int32} = a + b")
      Console.WriteLine(uc.Eval("5 OpA 4 * 10"))
      Console.WriteLine(uc.Eval("5 OpB 4 * 10"))
      
      '// Associativity
      Console.WriteLine("------ Associativity -------")
      uc.Define("Associativity: LeftToRight ~~ Operator: {x} OpX {y} = x / y")
      uc.Define("Associativity: RightToLeft ~~ Operator: {x} OpY {y} = x / y")
      Console.WriteLine(uc.Eval("3 OpX 4 OpX 5"))
      Console.WriteLine(uc.Eval("3 OpY 4 OpY 5"))
   End Sub
End Module
				
			
------ Basic examples -------
15
50
12300
------ End user definition -------
987000
------ Boolean format -------
true
false
1
false
TotallyTrue
CompletelyFalse
55
CompletelyFalse
------ Format -------
Answer: <3>
Answer: <String Value --> Hello world!>
Answer: <Additional format: 3>
The Answer: <Additional format: 3>
The Answer: <3>
------ Bootstrap -------
7b
0x7B
7b
------ Overwrite -------
5
50
55
-------
25
2500
2525
------ Lock -------
555
3.14
222
Value cannot be assigned here
222
3.14
-------
105
205
305
205
------ Tokens -------
Undefined identifier
Undefined identifier
9
15
------ Precedence -------
45
90
------ Associativity -------
0.15
3.75