DataType

# CString

<div class="rst-class">

forsearch

</div>

DataType

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Notes

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### String

You can assign a `String</api/data_types/string>` variable to a <span class="title-ref">CString</span> and it will be terminated with a null automatically. This only converts the String up to the first Null (0) byte value. <span class="title-ref">CString</span> implicitly converts to String when assigned to String variables.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Text

To convert a Text value to a <span class="title-ref">CString</span>, call Text.ToCString. This will only convert the Text up to the first Null (0) byte value. To convert a <span class="title-ref">CString</span> to a Text value, call Text.FromCString.

## Sample code

Declare a <span class="title-ref">CString</span> variable:

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

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`String</api/data_types/string>` data type

</div>
