Customizing token definitions (e.g., treating hyphens as part of a word).
ID: 246
See: Tokens
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// Now capture it using the {@Alpha} category
t.FromTo("{@Alpha:w}", "<{w}>");
Console.WriteLine("Before:");
Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon."));
// Define a new token pattern for hyphenated words
// We assign it to the 'AlphaNumeric' category so it behaves like a word
t.Tokens.Add("[a-zA-Z-]+", TokenType.AlphaNumeric);
Console.WriteLine("After:");
Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon."));
Before:
1. <Start>-<Up> 'big ideas' <well>-<knwon>.
After:
1. <Start-Up> 'big ideas' <well-knwon>. using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // Now capture it using the {@Alpha} category t.FromTo("{@Alpha:w}", "<{w}>"); Console.WriteLine("Before:"); Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon.")); // Define a new token pattern for hyphenated words // We assign it to the 'AlphaNumeric' category so it behaves like a word t.Tokens.Add("[a-zA-Z-]+", TokenType.AlphaNumeric); Console.WriteLine("After:"); Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon."));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// Now capture it using the {@Alpha} category
t.FromTo("{@Alpha:w}", "<{w}>");
cout << "Before:" << endl;
cout << t.Transform("1. Start-Up 'big ideas' well-knwon.") << endl;
// Define a new token pattern for hyphenated words
// We assign it to the 'AlphaNumeric' category so it behaves like a word
t.Tokens().Add("[a-zA-Z-]+", TokenType::AlphaNumeric);
cout << "After:" << endl;
cout << t.Transform("1. Start-Up 'big ideas' well-knwon.") << endl;
}
Before:
1. <Start>-<Up> 'big ideas' <well>-<knwon>.
After:
1. <Start-Up> 'big ideas' <well-knwon>. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // Now capture it using the {@Alpha} category t.FromTo("{@Alpha:w}", "<{w}>"); cout << "Before:" << endl; cout << t.Transform("1. Start-Up 'big ideas' well-knwon.") << endl; // Define a new token pattern for hyphenated words // We assign it to the 'AlphaNumeric' category so it behaves like a word t.Tokens().Add("[a-zA-Z-]+", TokenType::AlphaNumeric); cout << "After:" << endl; cout << t.Transform("1. Start-Up 'big ideas' well-knwon.") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// Now capture it using the {@Alpha} category
t.FromTo("{@Alpha:w}", "<{w}>")
Console.WriteLine("Before:")
Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon."))
'// Define a new token pattern for hyphenated words
'// We assign it to the 'AlphaNumeric' category so it behaves like a word
t.Tokens.Add("[a-zA-Z-]+", TokenType.AlphaNumeric)
Console.WriteLine("After:")
Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon."))
End Sub
End Module
Before:
1. <Start>-<Up> 'big ideas' <well>-<knwon>.
After:
1. <Start-Up> 'big ideas' <well-knwon>. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// Now capture it using the {@Alpha} category t.FromTo("{@Alpha:w}", "<{w}>") Console.WriteLine("Before:") Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon.")) '// Define a new token pattern for hyphenated words '// We assign it to the 'AlphaNumeric' category so it behaves like a word t.Tokens.Add("[a-zA-Z-]+", TokenType.AlphaNumeric) Console.WriteLine("After:") Console.WriteLine(t.Transform("1. Start-Up 'big ideas' well-knwon.")) End Sub End Module