A practical example sanitizing user input by removing script tags and normalizing excess whitespace in a single pass.

ID: 1142

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// Rule 1: Remove script tags and their content (case-insensitive, multi-line)
t.FromTo("<script>{content}</script>", "");
t.DefaultRuleSet.SetCaseSensitive(false).SetStatementSensitive(false);

// Rule 2: Normalize one or more whitespace characters to a single space
t.FromTo("{@Whitespace:ws}", " ");

// Transform the input in one go and print the result
t.Text = "  Welcome!  <SCRIPT>alert('bad');</SCRIPT>Please enjoy.  ";
Console.WriteLine($"Sanitized: '{t.Transform()}'");
				
			
Sanitized: ' Welcome! Please enjoy. '
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // Rule 1: Remove script tags and their content (case-insensitive, multi-line)
   t.FromTo("<script>{content}</script>", "");
   t.DefaultRuleSet().SetCaseSensitive(false).SetStatementSensitive(false);

   // Rule 2: Normalize one or more whitespace characters to a single space
   t.FromTo("{@Whitespace:ws}", " ");

   // Transform the input in one go and print the result
   t.Text("  Welcome!  <SCRIPT>alert('bad');</SCRIPT>Please enjoy.  ");
   cout << "Sanitized: '" << t.Transform() << "'" << endl;
}
				
			
Sanitized: ' Welcome! Please enjoy. '
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// Rule 1: Remove script tags and their content (case-insensitive, multi-line)
      t.FromTo("<script>{content}</script>", "")
      t.DefaultRuleSet.SetCaseSensitive(false).SetStatementSensitive(false)
      
      '// Rule 2: Normalize one or more whitespace characters to a single space
      t.FromTo("{@Whitespace:ws}", " ")
      
      '// Transform the input in one go and print the result
      t.Text = "  Welcome!  <SCRIPT>alert('bad');</SCRIPT>Please enjoy.  "
      Console.WriteLine($"Sanitized: '{t.Transform()}'")
   End Sub
End Module
				
			
Sanitized: ' Welcome! Please enjoy. '