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..."); 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));
#include
#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..."); #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; }
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..."); 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