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.
ToString(string)
Method
Product:
Class:
Parses and converts an input string into a new string, formatted according to the rules of the specific data type.
Syntax
Parameters
Return
string
The resulting string after parsing the input and reformatting it based on the data type's rules.
Remarks
The ToString method is a powerful, type-aware parsing utility. Unlike a typical ToString function that serializes an object's current state, this method takes an external string and interprets it according to the rules of the DataType object it is called on.
This is particularly useful for data normalization and validation, as it can convert a single string representation into the canonical format for a given type.
For example, when called on an unsigned 8-bit integer type, it correctly handles overflow wrapping:
// The Int8u type interprets -1 as its max value (255)var dt = uc.DataTypeOf(BuiltInType.Integer_8u);Console.WriteLine(dt.ToString("-1")); // Output: 255ToString vs. EvalStr
It is crucial to distinguish this method from EvalStr:
DataType.ToString(string): Parses a single literal value. It does not evaluate expressions. For example,uc.DataTypeOf("Int").ToString("1+1")would likely fail to parse "1+1" as a valid integer and return "0".uc.EvalStr(string): Parses and evaluates a full expression. For example,uc.EvalStr("1+1")returns "2".
⚖️ Comparative Analysis
In languages like C#, parsing is a static operation tied to a specific type (e.g., int.Parse(), bool.Parse()). This requires compile-time knowledge of the target type.
uCalc's approach is dynamic. You can hold a DataType object in a variable and call ToString on it without knowing at compile time which specific type it represents. This enables the creation of generic, powerful data validation and conversion routines that can be configured at runtime.
See also: ToString(pointer), the overload which converts a value from a memory address.
Examples
Using ToString to convert a value to a string
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"));
-1
255
65535
true
-1 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl;
}
-1
255
65535
true
-1 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"))
End Sub
End Module
-1
255
65535
true
-1 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1")) End Sub End Module