Demonstrates interoperability between `Transformer` and `String` objects, and chaining methods to create nested views.
ID: 1159
See: (Constructor)
using uCalcSoftware;
var uc = new uCalc();
// Create a transformer and perform a transformation
var t = uc.NewTransformer();
t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;";
t.FromTo("1", "100");
t.Transform();
// --- Interoperability and Chaining ---
var Pattern = "if ({cond})";
// 1. Create a uCalc.String from a Transformer.
// 2. Chain .After() to get a "live view" of the text after the pattern.
var s = new uCalc.String(t);
var after_first_if = s.After(Pattern);
Console.WriteLine(after_first_if.Text);
// 3. Chain another .After() on the child string.
var after_second_if = after_first_if.After(Pattern);
Console.WriteLine(after_second_if.Text);
// --- String to Transformer Conversion ---
// 4. Create a uCalc.String and assign it text.
var s2 = new uCalc.String();
s2 = "This is a test";
// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
var t2 = new uCalc.Transformer(s2);
Console.WriteLine(t2.Text);
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test using uCalcSoftware; var uc = new uCalc(); // Create a transformer and perform a transformation var t = uc.NewTransformer(); t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"; t.FromTo("1", "100"); t.Transform(); // --- Interoperability and Chaining --- var Pattern = "if ({cond})"; // 1. Create a uCalc.String from a Transformer. // 2. Chain .After() to get a "live view" of the text after the pattern. var s = new uCalc.String(t); var after_first_if = s.After(Pattern); Console.WriteLine(after_first_if.Text); // 3. Chain another .After() on the child string. var after_second_if = after_first_if.After(Pattern); Console.WriteLine(after_second_if.Text); // --- String to Transformer Conversion --- // 4. Create a uCalc.String and assign it text. var s2 = new uCalc.String(); s2 = "This is a test"; // 5. Create a Transformer from the uCalc.String to use transformer-specific methods. var t2 = new uCalc.Transformer(s2); Console.WriteLine(t2.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Create a transformer and perform a transformation
auto t = uc.NewTransformer();
t.Text("if (x > 3) y = x * 2; else if(x == 5) y = x - 1;");
t.FromTo("1", "100");
t.Transform();
// --- Interoperability and Chaining ---
auto Pattern = "if ({cond})";
// 1. Create a uCalc.String from a Transformer.
// 2. Chain .After() to get a "live view" of the text after the pattern.
uCalc::String s(t);
auto after_first_if = s.After(Pattern);
cout << after_first_if.Text() << endl;
// 3. Chain another .After() on the child string.
auto after_second_if = after_first_if.After(Pattern);
cout << after_second_if.Text() << endl;
// --- String to Transformer Conversion ---
// 4. Create a uCalc.String and assign it text.
uCalc::String s2;
s2 = "This is a test";
// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
uCalc::Transformer t2(s2);
cout << t2.Text() << endl;
}
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Create a transformer and perform a transformation auto t = uc.NewTransformer(); t.Text("if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"); t.FromTo("1", "100"); t.Transform(); // --- Interoperability and Chaining --- auto Pattern = "if ({cond})"; // 1. Create a uCalc.String from a Transformer. // 2. Chain .After() to get a "live view" of the text after the pattern. uCalc::String s(t); auto after_first_if = s.After(Pattern); cout << after_first_if.Text() << endl; // 3. Chain another .After() on the child string. auto after_second_if = after_first_if.After(Pattern); cout << after_second_if.Text() << endl; // --- String to Transformer Conversion --- // 4. Create a uCalc.String and assign it text. uCalc::String s2; s2 = "This is a test"; // 5. Create a Transformer from the uCalc.String to use transformer-specific methods. uCalc::Transformer t2(s2); cout << t2.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Create a transformer and perform a transformation
Dim t = uc.NewTransformer()
t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;"
t.FromTo("1", "100")
t.Transform()
'// --- Interoperability and Chaining ---
Dim Pattern = "if ({cond})"
'// 1. Create a uCalc.String from a Transformer.
'// 2. Chain .After() to get a "live view" of the text after the pattern.
Dim s As New uCalc.String(t)
Dim after_first_if = s.After(Pattern)
Console.WriteLine(after_first_if.Text)
'// 3. Chain another .After() on the child string.
Dim after_second_if = after_first_if.After(Pattern)
Console.WriteLine(after_second_if.Text)
'// --- String to Transformer Conversion ---
'// 4. Create a uCalc.String and assign it text.
Dim s2 As New uCalc.String()
s2 = "This is a test"
'// 5. Create a Transformer from the uCalc.String to use transformer-specific methods.
Dim t2 As New uCalc.Transformer(s2)
Console.WriteLine(t2.Text)
End Sub
End Module
y = x * 2; else if(x == 5) y = x - 100;
y = x - 100;
This is a test Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Create a transformer and perform a transformation Dim t = uc.NewTransformer() t.Text = "if (x > 3) y = x * 2; else if(x == 5) y = x - 1;" t.FromTo("1", "100") t.Transform() '// --- Interoperability and Chaining --- Dim Pattern = "if ({cond})" '// 1. Create a uCalc.String from a Transformer. '// 2. Chain .After() to get a "live view" of the text after the pattern. Dim s As New uCalc.String(t) Dim after_first_if = s.After(Pattern) Console.WriteLine(after_first_if.Text) '// 3. Chain another .After() on the child string. Dim after_second_if = after_first_if.After(Pattern) Console.WriteLine(after_second_if.Text) '// --- String to Transformer Conversion --- '// 4. Create a uCalc.String and assign it text. Dim s2 As New uCalc.String() s2 = "This is a test" '// 5. Create a Transformer from the uCalc.String to use transformer-specific methods. Dim t2 As New uCalc.Transformer(s2) Console.WriteLine(t2.Text) End Sub End Module