# Diference Between CString & String

**URL:** <https://clarionhub.com/t/diference-between-cstring-string/249>\
**Category:** questions\
**Created:** [October 29, 2014, 11:21am UTC](https://clarionhub.com/t/diference-between-cstring-string/249 "2014-10-29T11:21:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [May 29, 2015, 7:50pm UTC](https://clarionhub.com/t/diference-between-cstring-string/249/5 "2015-05-29T19:50:21Z")

</div>

A STRING is padded with spaces  
A CSTRING is null terminated (where a null is a ‘\<0\>’)

```
MyString STRING(4)
MyCSTRING CSTRING(4)
  CODE
  MyString = 'Hi'
  MyCSTRING = 'Hi'

```

If you looked at the bytes, you’d see  
MyString has ‘H’, ‘i’, ‘\<32\>, ‘\<32\>’ ! note: \<32\> is a space  
MyCstring has ‘H’, ‘i’,’\<0\>', UNDEFINED

Also note that the MyCstring(4) can only hold 3 characters as the ‘\<0\>’ is counted as one  
Whereas the MyString(4) can hold 4 characters

Nearly all APIs using CSTRING

A benefit of CSTRINGs is that you don’t need to constantly clip them

```
LongerCString CSTRING(16)
   CODE
   MyCstring = 'Hi'
   MyCstring = MyCstring & ' There'

```

Now MyCstring will have ‘Hi There’ followed by a ‘\<0\>’ and then undefined bytes

On the other hand:

```
LongerString STRING(15)
  CODE
  LongerString = 'Hi'
  LongerString = LongerString & ' There'

```

The problem here is that the first line set LongerString to ‘Hi ’  
‘Hi’ & ALL(’\<32\>',13)  
So the 2nd line makes no change, as it just overflows the variable  
Instead you need to write

```
  LongerString = CLIP(LongerString) & ' There'

```

Now you can put spaces into a CSTRING  
So if you write

```
MyCstring CSTRING(16)
MyString STRING(15)
  CODE
  MyString = 'Hi' ! <-- remember this will pad with spaces
  MyCString = MyString ! <-- copied in the spaces

```

---

_[View the full topic](https://clarionhub.com/t/diference-between-cstring-string/249)._
