Programming Reference Manual
 
Syntax
 
string = stringclassobject.toString
 
Description
Returns the textual contents of the StringClass instance, automatically normalised to the standard Windows-1252 (ANSI) encoding used internally by Tradium Basic Script and CCL.
 
Before returning the value, toString invokes isUTF8 to determine whether the underlying buffer is a UTF-8 byte sequence; when this is the case, the buffer is decoded by an internal call to fromUTF8 and the decoded result is returned. When the buffer is not UTF-8 encoded — including the case of plain ASCII content, which is treated here as already-native rather than as UTF-8 requiring conversion — the contents of the buffer are returned unchanged. toString is the recommended general-purpose accessor for retrieving the value of a StringClass instance in script logic, because it removes the need for the script to know in advance which encoding the buffer holds and removes the need to perform the detection and conversion explicitly.
 
In the great majority of scripts that consume external data — REST API responses, XML or JSON payloads, files written by a modern editor, or output from another platform — toString is sufficient and no further encoding handling is required. The fromUTF8 and isUTF8 methods remain available for situations where the script must direct the detection and conversion process itself, for example when processing mixed-encoding content or when the script needs to distinguish between native and converted values. The contents of the StringClass instance itself are not modified by toString; only the returned value is normalised.
See Also
Example
Sub Main
Dim oS As StringClass
Dim sFromAPI$
 
' Buffer as it would be received from an external REST API (UTF-8).
sFromAPI$ = "Caf" & Chr$(195) & Chr$(169) & " Br" & Chr$(195) & Chr$(187) & "l" & Chr$(195) & Chr$(169)
 
Set oS = New StringClass
oS.Value = sFromAPI$
 
' toString detects the encoding and normalises automatically;
' a buffer that is already native is returned unchanged.
Debug.Print "Normalised value: "; oS.toString
 
Set oS = Nothing
End Sub