Difference between revisions of "CString"

From Xojo Documentation

 
Line 21: Line 21:
 
Declare a CString variable:
 
Declare a CString variable:
 
<rbcode>
 
<rbcode>
Dim s As String = "Hello!"
+
Var s As String = "Hello!"
Dim cs As CString = s
+
Var cs As CString = s
 
</rbcode>
 
</rbcode>
  

Latest revision as of 23:56, 20 November 2019

Data Type


A null-terminated, C-style String for use when working with OS APIs.

Notes

A CString is a low-level C-style string for use with Declares and MemoryBlocks. CStrings created from Text or Xojo.Core.MemoryBlock and CStrings stored in Autos are reference-counted and safe to keep around. Otherwise, if the string/object that the CString originates from is tied to the lifetime of that string/object.

String

You can assign a String variable to a CString and it will be terminated with a null automatically. This only converts the String up to the first Null (0) byte value. CString implicitly converts to String when assigned to String variables.

Text

To convert a Text value to a CString, call Text.ToCString. This will only convert the Text up to the first Null (0) byte value. To convert a CString to a Text value, call Text.FromCString.

Sample Code

Declare a CString variable:

Var s As String = "Hello!"
Var cs As CString = s

See Also

String data type