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.
Between
Method
Product:
Class:
Creates a live, modifiable view of the substring located between two specified patterns.
Syntax
Parameters
Return
String
A new uCalc.String object representing a live, modifiable view into the portion of the parent string between the specified patterns. Returns an empty string object if the patterns are not found.
Remarks
✂️ Extracting Text Between Two Patterns
The Between method finds the text located between two specified patterns and returns it as a new uCalc.String object. This is a fundamental tool for parsing structured data and is a core part of the fluent, chainable API, often used with methods like After and Before.
✨ The "Live View" Concept
The most important feature of this method is that it does not return a simple, disconnected substring. Instead, it returns a live, modifiable view into the parent string. This means:
- Any modifications made to the child string (the returned view) will directly affect the content of the original parent string.
- This allows for powerful, in-place editing of specific sections of a larger document without the overhead of creating and rejoining substrings.
⚙️ Parameters
startPattern&stopPattern: These define the boundaries of the text to be extracted. The returned view contains only the content between these boundaries, not including the boundaries themselves.startNth&stopNth: These 1-based indices allow you to handle documents with repeated patterns. For example,Between("(", ")", 2)would find the text inside the second set of parentheses.
If either pattern is not found, the method returns an empty uCalc.String object without raising an error.
💡 Why uCalc? (Comparative Analysis)
In a standard language like C#, extracting text between two markers requires a manual, multi-step process involving IndexOf and Substring.
C# Manual Approach:
string text = "Config{value=123}";int startIndex = text.IndexOf("{") + 1;int endIndex = text.IndexOf("}");if (startIndex != 0 && endIndex != -1){ string value = text.Substring(startIndex, endIndex - startIndex); // 'value' is a new, disconnected string: "value=123"}This approach is imperative, character-based, and creates disconnected data. uCalc.String provides a more powerful, declarative, and integrated solution:
The uCalc Advantage:
var s = new uCalc.String("Config{value=123}");var valueView = s.Between("{", "}"); // Returns a live, token-aware view// Modifying the view changes the original string 's'valueView.Replace("123", "CHANGED");Console.WriteLine(s); // Output: Config{value=CHANGED}This ability to create live, token-aware, chainable views is a key differentiator, enabling a more fluid and powerful style of text manipulation that is not possible with standard string libraries.
Examples
A succinct example demonstrating how to extract text contained within a pair of parentheses.
using uCalcSoftware;
var uc = new uCalc();
using (var s = new uCalc.String("Data (important) more data")) {
// Get the text between the opening and closing parenthesis
var content = s.Between("(", ")");
Console.WriteLine(content);
}
important using uCalcSoftware; var uc = new uCalc(); using (var s = new uCalc.String("Data (important) more data")) { // Get the text between the opening and closing parenthesis var content = s.Between("(", ")"); Console.WriteLine(content); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::String s("Data (important) more data");
s.Owned(); // Causes s to be released when it goes out of scope
// Get the text between the opening and closing parenthesis
auto content = s.Between("(", ")");
cout << content << endl;
}
}
important #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::String s("Data (important) more data"); s.Owned(); // Causes s to be released when it goes out of scope // Get the text between the opening and closing parenthesis auto content = s.Between("(", ")"); cout << content << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using s As New uCalc.String("Data (important) more data")
'// Get the text between the opening and closing parenthesis
Dim content = s.Between("(", ")")
Console.WriteLine(content)
End Using
End Sub
End Module
important Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using s As New uCalc.String("Data (important) more data") '// Get the text between the opening and closing parenthesis Dim content = s.Between("(", ")") Console.WriteLine(content) End Using End Sub End Module
A practical example of parsing a value from a simple key-value pair in a configuration string.
using uCalcSoftware;
var uc = new uCalc();
using (var s = new uCalc.String("User: admin; Role: user; Department: Sales;")) {
// Extract the text between 'Department: ' and the trailing semicolon
var department = s.Between("Department: ", ";");
Console.WriteLine($"Department is '{department}'");
}
Department is ' Sales' using uCalcSoftware; var uc = new uCalc(); using (var s = new uCalc.String("User: admin; Role: user; Department: Sales;")) { // Extract the text between 'Department: ' and the trailing semicolon var department = s.Between("Department: ", ";"); Console.WriteLine($"Department is '{department}'"); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::String s("User: admin; Role: user; Department: Sales;");
s.Owned(); // Causes s to be released when it goes out of scope
// Extract the text between 'Department: ' and the trailing semicolon
auto department = s.Between("Department: ", ";");
cout << "Department is '" << department << "'" << endl;
}
}
Department is ' Sales' #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::String s("User: admin; Role: user; Department: Sales;"); s.Owned(); // Causes s to be released when it goes out of scope // Extract the text between 'Department: ' and the trailing semicolon auto department = s.Between("Department: ", ";"); cout << "Department is '" << department << "'" << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using s As New uCalc.String("User: admin; Role: user; Department: Sales;")
'// Extract the text between 'Department: ' and the trailing semicolon
Dim department = s.Between("Department: ", ";")
Console.WriteLine($"Department is '{department}'")
End Using
End Sub
End Module
Department is ' Sales' Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using s As New uCalc.String("User: admin; Role: user; Department: Sales;") '// Extract the text between 'Department: ' and the trailing semicolon Dim department = s.Between("Department: ", ";") Console.WriteLine($"Department is '{department}'") End Using End Sub End Module