Using **Conditional Blocks** to format an optional title.
ID: 234
See: Replacement
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// Pattern: Name followed optionally by a Title in parens.
t.FromTo("Name: {n} [({title})]",
"User: {n} {title:[Title: {title}]}");
// Case 1: Title exists
Console.WriteLine(t.Transform("Name: Alice (Manager)"));
// Case 2: Title missing
Console.WriteLine(t.Transform("Name: Bob"));
// (The entire "[Title: ...]" block is omitted)
User: Alice [Title: Manager]
User: Bob using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // Pattern: Name followed optionally by a Title in parens. t.FromTo("Name: {n} [({title})]", "User: {n} {title:[Title: {title}]}"); // Case 1: Title exists Console.WriteLine(t.Transform("Name: Alice (Manager)")); // Case 2: Title missing Console.WriteLine(t.Transform("Name: Bob")); // (The entire "[Title: ...]" block is omitted)
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// Pattern: Name followed optionally by a Title in parens.
t.FromTo("Name: {n} [({title})]",
"User: {n} {title:[Title: {title}]}");
// Case 1: Title exists
cout << t.Transform("Name: Alice (Manager)") << endl;
// Case 2: Title missing
cout << t.Transform("Name: Bob") << endl;
// (The entire "[Title: ...]" block is omitted)
}
User: Alice [Title: Manager]
User: Bob #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // Pattern: Name followed optionally by a Title in parens. t.FromTo("Name: {n} [({title})]", "User: {n} {title:[Title: {title}]}"); // Case 1: Title exists cout << t.Transform("Name: Alice (Manager)") << endl; // Case 2: Title missing cout << t.Transform("Name: Bob") << endl; // (The entire "[Title: ...]" block is omitted) }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// Pattern: Name followed optionally by a Title in parens.
t.FromTo("Name: {n} [({title})]",
"User: {n} {title:[Title: {title}]}")
'// Case 1: Title exists
Console.WriteLine(t.Transform("Name: Alice (Manager)"))
'// Case 2: Title missing
Console.WriteLine(t.Transform("Name: Bob"))
'// (The entire "[Title: ...]" block is omitted)
End Sub
End Module
User: Alice [Title: Manager]
User: Bob Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// Pattern: Name followed optionally by a Title in parens. t.FromTo("Name: {n} [({title})]", "User: {n} {title:[Title: {title}]}") '// Case 1: Title exists Console.WriteLine(t.Transform("Name: Alice (Manager)")) '// Case 2: Title missing Console.WriteLine(t.Transform("Name: Bob")) '// (The entire "[Title: ...]" block is omitted) End Sub End Module