Converts a value at a specified memory address to its string representation, optionally applying custom formatting rules.
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 string representation of the value at the specified address.
Syntax (Overload - Custom Format Expression): ToString(POINTER valuePtr, string formatString)
Parameters (Overload):
valuePtr - POINTER - A pointer to the memory location of the value to be converted.formatString - string - A formatting expression in the form of "Result = [expression]" that manipulates the output before returning it.Return:string - The string representation of the value at the specified address.
This overload of ToString is a powerful low-level utility that converts a raw value in memory into a human-readable string. Its behavior is dictated by the DataType object it is called on. For example, calling ToString on an Integer_8u DataType will interpret the byte at the given address as an unsigned 8-bit integer and format it accordingly.
This method is primarily used in advanced scenarios, especially within callbacks where you might receive a value's memory address via ArgAddr() instead of the value itself.
ToString provides two primary approaches for controlling how the converted result is formatted:
FormatStyle Enum & Precision:For quick, standardized numeric formatting, you can pass a FormatStyle enum (such as FormatStyle.Fixed or FormatStyle.Hex) along with an optional precision integer.
FormatStyle.Default automatically applies any global user-defined formatting established via uCalc.Format() for this data type.FormatStyle.None bypasses global formatters and returns the raw value.Custom Format Expressions:For granular control over a specific conversion, you can pass a custom format expression (e.g., "Result = Format('${:.2f}', double(Result))"). Because Result holds the output in string form, numeric values should be converted when passed into numeric formatting specifiers.
.ToString() / std::to_stringIn languages like C# or C++, string conversion is tied to the compile-time type of a variable. myInt.ToString() knows it's an integer because myInt was declared as one.
uCalc's DataType.ToString(pointer) is different; it's a form of dynamic dispatch. The formatting logic is determined at runtime by the DataType object you call it on, not by the type of the pointer. This allows you to interpret the same block of memory in different ways, which is impossible with static language features.
using uCalcSoftware;
var uc = new uCalc();
// Assume 'ptr' points to a 4-byte block in memory holding the integer 1000.
var int32Type = uc.DataTypeOf("Int32");
// Interpret the memory as a standard integer
Console.WriteLine(int32Type.ToString(ptr)); // Output: 1000
// If you had a custom Hex type, you could interpret the same memory differently:
// var hexType = uc.DataTypeOf("Hex");
// wl(hexType.ToString(ptr)); // Would output: 3E8
This demonstrates a level of runtime introspection and flexibility that goes beyond typical language-level string conversion.
ID: 1481
using uCalcSoftware;
var uc = new uCalc();
var myVar = uc.DefineVariable("myVar = 255.5");
var ptr = myVar.ValueAddr();
// Get the DataType object for Double
var doubleType = uc.DataTypeOf("Double");
// Read from memory and format as Fixed with 2 decimal places
Console.WriteLine(doubleType.ToString(ptr, FormatStyle.Fixed, 2));
// Read from memory and format with a custom pattern
Console.WriteLine(doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))"));
255.50
-- 255.5--
using uCalcSoftware; var uc = new uCalc(); var myVar = uc.DefineVariable("myVar = 255.5"); var ptr = myVar.ValueAddr(); // Get the DataType object for Double var doubleType = uc.DataTypeOf("Double"); // Read from memory and format as Fixed with 2 decimal places Console.WriteLine(doubleType.ToString(ptr, FormatStyle.Fixed, 2)); // Read from memory and format with a custom pattern Console.WriteLine(doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto myVar = uc.DefineVariable("myVar = 255.5");
auto ptr = myVar.ValueAddr();
// Get the DataType object for Double
auto doubleType = uc.DataTypeOf("Double");
// Read from memory and format as Fixed with 2 decimal places
cout << doubleType.ToString(ptr, FormatStyle::Fixed, 2) << endl;
// Read from memory and format with a custom pattern
cout << doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))") << endl;
}
255.50
-- 255.5--
#include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto myVar = uc.DefineVariable("myVar = 255.5"); auto ptr = myVar.ValueAddr(); // Get the DataType object for Double auto doubleType = uc.DataTypeOf("Double"); // Read from memory and format as Fixed with 2 decimal places cout << doubleType.ToString(ptr, FormatStyle::Fixed, 2) << endl; // Read from memory and format with a custom pattern cout << doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim myVar = uc.DefineVariable("myVar = 255.5")
Dim ptr = myVar.ValueAddr()
'// Get the DataType object for Double
Dim doubleType = uc.DataTypeOf("Double")
'// Read from memory and format as Fixed with 2 decimal places
Console.WriteLine(doubleType.ToString(ptr, FormatStyle.Fixed, 2))
'// Read from memory and format with a custom pattern
Console.WriteLine(doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))"))
End Sub
End Module
255.50
-- 255.5--
Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim myVar = uc.DefineVariable("myVar = 255.5") Dim ptr = myVar.ValueAddr() '// Get the DataType object for Double Dim doubleType = uc.DataTypeOf("Double") '// Read from memory and format as Fixed with 2 decimal places Console.WriteLine(doubleType.ToString(ptr, FormatStyle.Fixed, 2)) '// Read from memory and format with a custom pattern Console.WriteLine(doubleType.ToString(ptr, "Result = Format('--{:6.1f}--', double(Result))")) End Sub End Module
ID: 16
using uCalcSoftware;
var uc = new uCalc();
static void MyFunction(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc ------");
// Retrieve standard 32-bit and 64-bit integer arguments directly
Console.WriteLine(cb.ArgInt32(1));
Console.WriteLine(cb.ArgInt64(2));
// Retrieve the value of a pointer argument by referencing its exact data type.
Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3)));
// The Item object correctly identifies the type before conversion
Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4)));
}
static void MyFunction2(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc2 ------");
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1)));
}
static void MyFunction3(uCalc.Callback cb) {
var uc = cb.uCalc;
Console.WriteLine("------ MyFunc3 ------");
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1)));
}
uc.DefineVariable("x As Int = 123"); // Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction);
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
uc.DefineVariable("x2 As Int8 = -123");
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)");
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2);
uc.Eval("MyFunc2(xPtr2)");
uc.DefineVariable("x3 As Int16 = 1234");
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)");
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3);
uc.Eval("MyFunc3(xPtr3)");
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 using uCalcSoftware; var uc = new uCalc(); static void MyFunction(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc ------"); // Retrieve standard 32-bit and 64-bit integer arguments directly Console.WriteLine(cb.ArgInt32(1)); Console.WriteLine(cb.ArgInt64(2)); // Retrieve the value of a pointer argument by referencing its exact data type. Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3))); // The Item object correctly identifies the type before conversion Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4))); } static void MyFunction2(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc2 ------"); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1))); } static void MyFunction3(uCalc.Callback cb) { var uc = cb.uCalc; Console.WriteLine("------ MyFunc3 ------"); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1))); } uc.DefineVariable("x As Int = 123"); // Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)"); uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction); uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)"); uc.DefineVariable("x2 As Int8 = -123"); uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)"); uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2); uc.Eval("MyFunc2(xPtr2)"); uc.DefineVariable("x3 As Int16 = 1234"); uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)"); uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3); uc.Eval("MyFunc3(xPtr3)");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
void ucalc_call MyFunction(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc ------" << endl;
// Retrieve standard 32-bit and 64-bit integer arguments directly
cout << cb.ArgInt32(1) << endl;
cout << cb.ArgInt64(2) << endl;
// Retrieve the value of a pointer argument by referencing its exact data type.
cout << uc.ItemOf("Int8").DataType().ToString(cb.ArgAddr(3)) << endl;
// The Item object correctly identifies the type before conversion
cout << uc.ItemOf("Int").DataType().ToString(cb.ArgPtr(4)) << endl;
}
void ucalc_call MyFunction2(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc2 ------" << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString(cb.ArgPtr(1)) << endl;
}
void ucalc_call MyFunction3(uCalcBase::Callback cb) {
auto uc = cb.uCalc();
cout << "------ MyFunc3 ------" << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_16).ToString(cb.ArgPtr(1)) << endl;
}
int main() {
uCalc uc;
uc.DefineVariable("x As Int = 123"); // Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)");
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction);
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)");
uc.DefineVariable("x2 As Int8 = -123");
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)");
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2);
uc.Eval("MyFunc2(xPtr2)");
uc.DefineVariable("x3 As Int16 = 1234");
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)");
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3);
uc.Eval("MyFunc3(xPtr3)");
}
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; void ucalc_call MyFunction(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc ------" << endl; // Retrieve standard 32-bit and 64-bit integer arguments directly cout << cb.ArgInt32(1) << endl; cout << cb.ArgInt64(2) << endl; // Retrieve the value of a pointer argument by referencing its exact data type. cout << uc.ItemOf("Int8").DataType().ToString(cb.ArgAddr(3)) << endl; // The Item object correctly identifies the type before conversion cout << uc.ItemOf("Int").DataType().ToString(cb.ArgPtr(4)) << endl; } void ucalc_call MyFunction2(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc2 ------" << endl; cout << uc.DataTypeOf(BuiltInType::Integer_8).ToString(cb.ArgPtr(1)) << endl; } void ucalc_call MyFunction3(uCalcBase::Callback cb) { auto uc = cb.uCalc(); cout << "------ MyFunc3 ------" << endl; cout << uc.DataTypeOf(BuiltInType::Integer_16).ToString(cb.ArgPtr(1)) << endl; } int main() { uCalc uc; uc.DefineVariable("x As Int = 123"); // Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)"); uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", MyFunction); uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)"); uc.DefineVariable("x2 As Int8 = -123"); uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)"); uc.DefineFunction("MyFunc2(d As Int8 Ptr)", MyFunction2); uc.Eval("MyFunc2(xPtr2)"); uc.DefineVariable("x3 As Int16 = 1234"); uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)"); uc.DefineFunction("MyFunc3(d As Int16 Ptr)", MyFunction3); uc.Eval("MyFunc3(xPtr3)"); }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub MyFunction(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc ------")
'// Retrieve standard 32-bit and 64-bit integer arguments directly
Console.WriteLine(cb.ArgInt32(1))
Console.WriteLine(cb.ArgInt64(2))
'// Retrieve the value of a pointer argument by referencing its exact data type.
Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3)))
'// The Item object correctly identifies the type before conversion
Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4)))
End Sub
Public Sub MyFunction2(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc2 ------")
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1)))
End Sub
Public Sub MyFunction3(ByVal cb As uCalc.Callback)
Dim uc = cb.uCalc
Console.WriteLine("------ MyFunc3 ------")
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1)))
End Sub
Public Sub Main()
Dim uc As New uCalc()
uc.DefineVariable("x As Int = 123") '// Int32
uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)")
uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", AddressOf MyFunction)
uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)")
uc.DefineVariable("x2 As Int8 = -123")
uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)")
uc.DefineFunction("MyFunc2(d As Int8 Ptr)", AddressOf MyFunction2)
uc.Eval("MyFunc2(xPtr2)")
uc.DefineVariable("x3 As Int16 = 1234")
uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)")
uc.DefineFunction("MyFunc3(d As Int16 Ptr)", AddressOf MyFunction3)
uc.Eval("MyFunc3(xPtr3)")
End Sub
End Module
------ MyFunc ------
1230
2
-1
123
------ MyFunc2 ------
-123
------ MyFunc3 ------
1234 Imports System Imports uCalcSoftware Public Module Program Public Sub MyFunction(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc ------") '// Retrieve standard 32-bit and 64-bit integer arguments directly Console.WriteLine(cb.ArgInt32(1)) Console.WriteLine(cb.ArgInt64(2)) '// Retrieve the value of a pointer argument by referencing its exact data type. Console.WriteLine(uc.ItemOf("Int8").DataType.ToString(cb.ArgAddr(3))) '// The Item object correctly identifies the type before conversion Console.WriteLine(uc.ItemOf("Int").DataType.ToString(cb.ArgPtr(4))) End Sub Public Sub MyFunction2(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc2 ------") Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8).ToString(cb.ArgPtr(1))) End Sub Public Sub MyFunction3(ByVal cb As uCalc.Callback) Dim uc = cb.uCalc Console.WriteLine("------ MyFunc3 ------") Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16).ToString(cb.ArgPtr(1))) End Sub Public Sub Main() Dim uc As New uCalc() uc.DefineVariable("x As Int = 123") '// Int32 uc.DefineVariable("xPtr As Int Ptr = AddressOf(x)") uc.DefineFunction("MyFunc(a As Int32, b As Int64, c As Byte, d As Int Ptr)", AddressOf MyFunction) uc.Eval("MyFunc(x*10, 1+1, 255, xPtr)") uc.DefineVariable("x2 As Int8 = -123") uc.DefineVariable("xPtr2 As Int8 Ptr = AddressOf(x2)") uc.DefineFunction("MyFunc2(d As Int8 Ptr)", AddressOf MyFunction2) uc.Eval("MyFunc2(xPtr2)") uc.DefineVariable("x3 As Int16 = 1234") uc.DefineVariable("xPtr3 As Int16 Ptr = AddressOf(x3)") uc.DefineFunction("MyFunc3(d As Int16 Ptr)", AddressOf MyFunction3) uc.Eval("MyFunc3(xPtr3)") End Sub End Module
This page last modified on: