uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Chaining Fluent Operations
Product:
Class:
Explains how to link multiple uCalc.String operations together in a single, readable statement to create powerful text-processing pipelines.
Remarks
[revisit]
⛓️ Chaining Fluent Operations
One of the most powerful features of the uCalc.String class is its fluent interface. This means that most methods return the uCalc.String object itself, allowing you to "chain" multiple operations together into a single, highly readable statement. This turns complex, multi-step text manipulations into concise, elegant pipelines.
The "Live View" Pipeline
The core concept behind chaining is the "live view." Methods that extract a portion of a string—like After(), Before(), and Between()—do not create a disconnected copy of the text. Instead, they return a new uCalc.String object that acts as a live, modifiable window or "view" into the original, parent string.
Think of it like focusing a lens:
- You start with the full document (the parent
uCalc.String). - You use
After("start")to create a view focused only on the text after your starting point. - You then chain
.Between("(", ")")onto that view, narrowing your focus even further to just the content inside the parentheses. - Finally, you apply an action like
.Replace("old", "new")to that focused view.
Because the view is live, the replacement you make is reflected directly in the original, parent string. This allows for incredibly powerful and efficient in-place editing.
💡 Why uCalc? (Comparative Analysis)
In traditional string manipulation, achieving the same result requires a verbose, multi-step process that creates temporary, disconnected string objects at each stage.
Typical C# Approach (Manual & Inefficient):
string text = "config user='admin' level=9";int userPos = text.IndexOf("user=") + 5; // Find startstring temp1 = text.Substring(userPos); // Create first temp stringint startQuote = temp1.IndexOf("'") + 1;int endQuote = temp1.IndexOf("'", startQuote);string username = temp1.Substring(startQuote, endQuote - startQuote); // Create second temp stringstring modifiedUsername = username.ToUpper(); // Create third temp stringstring final = text.Replace(username, modifiedUsername); // Create final stringThis code is hard to read, inefficient due to multiple string allocations, and prone to off-by-one errors.
The uCalc Fluent Approach (Clean & Efficient):
using (var s = new uCalc.String("config user='admin' level=9")) {s.After("user=").Between("'", "'").ToUpper();}This single line of code achieves the same result by creating a pipeline of live views. It is more readable, less error-prone, and performs better by avoiding the creation of intermediate string copies.