Restricts all subsequent find and transform operations to a specific character range within the source text.
Product:
Class:
Warning
uCalc API Preview Release Notice:The uCalc engine has successfully transitioned to modern cross-platform environments.The next phase envolves some structural changes, performance optimizations, and API refinements.The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.
The current Transformer object, allowing for a fluent, chainable interface.
(Note: This feature is not yet fully implemented and the final syntax may change.)
The Range method sets a "window" on the source text, restricting all subsequent find and transform operations to a specific sub-section of the string. This is a powerful performance optimization, as it avoids the memory allocation and copying overhead of creating a manual substring.
When you call Range, the Transformer records the specified startPosition and length. Any subsequent calls to methods like Find() or Transform() will operate only within this virtual boundary.
Match positions (StartPosition, EndPosition) returned by the Matches object remain relative to the original, full source string, preserving their global coordinates.
To clear the range and revert to searching the entire string, you can call Range(0, -1).
In a standard text processing workflow, to operate on a portion of a string, you must first create a substring.
Manual Substring Approach (Less Efficient):
using uCalcSoftware;
var uc = new uCalc();
// 1. Create a new string in memory.
var sub = myString.Substring(100, 50);
// 2. Perform the transformation on the new, smaller string.
var result = t.Transform(sub);
// 3. Manually stitch the result back into the original string.
This approach is inefficient for large documents because it involves memory allocation and data copying. If you need the original match coordinates, you must also manually add the starting offset back.
The uCalc Range Advantage:uCalc's Range method is a zero-copy operation. It doesn't create a new string. Instead, it adjusts the transformer's internal pointers to define a virtual search area. This is significantly faster and uses less memory, making it the ideal solution for parsing specific sections of large files, such as the body of an HTTP response or the content within a specific XML/HTML tag.
This page last modified on: