---
product: Chilkat
product_version: 11.7.0
language: delphix
language_label: Delphi ActiveX
class: CkString
class_name: TCkString
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/delphiCkStringRef.html
---
# Chilkat CkString — Delphi ActiveX — v11.7.0

> Chilkat 11.7.0 · language=delphix · class=CkString (TCkString)
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/CkString.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/delphix/guide.md`.

## Purpose

The Chilkat string class.

## Object creation, unlocking and error handling

**Object Creation**

```pascal
var
obj: TCkString;
...
begin
obj := TCkString.Create(Self);
...
// When finished, free the object instance.
obj.Free();
```

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Delphi ActiveX.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Member index

| Member | Kind | Signature |
|---|---|---|
| `NumArabic` | property, read-only | `property NumArabic: Integer readonly` |
| `NumAscii` | property, read-only | `property NumAscii: Integer readonly` |
| `NumCentralEuro` | property, read-only | `property NumCentralEuro: Integer readonly` |
| `NumChars` | property, read-only | `property NumChars: Integer readonly` |
| `NumChinese` | property, read-only | `property NumChinese: Integer readonly` |
| `NumCyrillic` | property, read-only | `property NumCyrillic: Integer readonly` |
| `NumGreek` | property, read-only | `property NumGreek: Integer readonly` |
| `NumHebrew` | property, read-only | `property NumHebrew: Integer readonly` |
| `NumJapanese` | property, read-only | `property NumJapanese: Integer readonly` |
| `NumKorean` | property, read-only | `property NumKorean: Integer readonly` |
| `NumLatin` | property, read-only | `property NumLatin: Integer readonly` |
| `NumThai` | property, read-only | `property NumThai: Integer readonly` |
| `SizeAnsi` | property, read-only | `property SizeAnsi: Integer readonly` |
| `SizeUtf8` | property, read-only | `property SizeUtf8: Integer readonly` |
| `Str` | property, read/write | `property Str: WideString` |
| `AnsiCharAt` | method | `function AnsiCharAt(index: Integer): Integer;` |
| `Append` | method | `procedure Append(str: WideString);` |
| `AppendEncoded` | method | `procedure AppendEncoded(str: WideString; encoding: WideString; charset: WideString);` |
| `AppendMultibyte` | method | `procedure AppendMultibyte(mbtext: OleVariant; charsetEncoding: WideString);` |
| `AppendToFile` | method | `function AppendToFile(path: WideString; charsetEncoding: WideString): Integer;` |
| `BeginsWith` | method | `function BeginsWith(str: WideString): Integer;` |
| `ChopAfter` | method | `procedure ChopAfter(findStr: WideString);` |
| `ChopBefore` | method | `procedure ChopBefore(findStr: WideString);` |
| `Clear` | method | `procedure Clear();` |
| `Contains` | method | `function Contains(substr: WideString): Integer;` |
| `EmitMultibyte` | method | `function EmitMultibyte(charsetEncoding: WideString): OleVariant;` |
| `EndsWith` | method | `function EndsWith(substr: WideString): Integer;` |
| `GetEncoded` | method | `function GetEncoded(binaryEncoding: WideString; charsetEncoding: WideString): WideString;` |
| `HtmlEntityDecode` | method | `procedure HtmlEntityDecode();` |
| `HtmlEntityEncode` | method | `procedure HtmlEntityEncode();` |
| `LastAnsiChar` | method | `function LastAnsiChar(): Integer;` |
| `Left` | method | `function Left(numChars: Integer): WideString;` |
| `Length` | method | `function Length(): Integer;` |
| `LoadFile` | method | `function LoadFile(path: WideString; charsetEncoding: WideString): Integer;` |
| `LoadXmlDoc` | method | `procedure LoadXmlDoc(xmlDocumentBytes: OleVariant);` |
| `Matches` | method | `function Matches(strPattern: WideString; caseSensitive: Integer): Integer;` |
| `Mid` | method | `function Mid(index: Integer; numChars: Integer): WideString;` |
| `Pluralize` | method | `procedure Pluralize();` |
| `Prepend` | method | `procedure Prepend(str: WideString);` |
| `PunyDecode` | method | `procedure PunyDecode();` |
| `PunyEncode` | method | `procedure PunyEncode();` |
| `RemoveAnsiChar` | method | `procedure RemoveAnsiChar(ch: Integer);` |
| `ReplaceAll` | method | `procedure ReplaceAll(findStr: WideString; replaceStr: WideString);` |
| `ReplaceAnsiChar` | method | `procedure ReplaceAnsiChar(findCh: Integer; replaceCh: Integer);` |
| `ReplaceFirst` | method | `procedure ReplaceFirst(findStr: WideString; replaceStr: WideString);` |
| `Right` | method | `function Right(numChars: Integer): WideString;` |
| `SaveToFile` | method | `function SaveToFile(path: WideString; charsetEncoding: WideString): Integer;` |
| `Shorten` | method | `procedure Shorten(numChars: Integer);` |
| `StrComp` | method | `function StrComp(str: WideString; caseSensitive: Integer): Integer;` |
| `StripHtml` | method | `procedure StripHtml();` |
| `ToCRLF` | method | `procedure ToCRLF();` |
| `ToLF` | method | `procedure ToLF();` |
| `Trim` | method | `procedure Trim();` |
| `Trim2` | method | `procedure Trim2();` |
| `TrimInside` | method | `procedure TrimInside();` |
| `Unpluralize` | method | `procedure Unpluralize();` |

## Properties

### CkString.NumArabic

`Chilkat 11.7.0 · delphix · CkString · NumArabic · property · read-only · since 9.5.0.25`

```pascal
property NumArabic: Integer readonly
```

The number of Arabic characters contained in this string.

### CkString.NumAscii

`Chilkat 11.7.0 · delphix · CkString · NumAscii · property · read-only · since 9.5.0.25`

```pascal
property NumAscii: Integer readonly
```

The number of us-ascii characters contained in this string.

### CkString.NumCentralEuro

`Chilkat 11.7.0 · delphix · CkString · NumCentralEuro · property · read-only · since 9.5.0.25`

```pascal
property NumCentralEuro: Integer readonly
```

The number of Central European and Eastern European characters found in this string. These are characters specific to Polish, Czech, Slovak, Hungarian, Slovene, Croatian, Serbian (Latin script), Romanian and Albanian.

### CkString.NumChars

`Chilkat 11.7.0 · delphix · CkString · NumChars · property · read-only`

```pascal
property NumChars: Integer readonly
```

The number of characters in the string.

### CkString.NumChinese

`Chilkat 11.7.0 · delphix · CkString · NumChinese · property · read-only · since 9.5.0.25`

```pascal
property NumChinese: Integer readonly
```

The number of Chinese characters contained in this string.

### CkString.NumCyrillic

`Chilkat 11.7.0 · delphix · CkString · NumCyrillic · property · read-only · since 9.5.0.25`

```pascal
property NumCyrillic: Integer readonly
```

The number of Cyrillic characters contained in this string. The Cyrillic alphabet also called azbuka, from the old name of the first two letters) is actually a family of alphabets, subsets of which are used by certain East and South Slavic languages `” Belarusian, Bulgarian, Macedonian, Russian, Rusyn, Serbian and Ukrainian`”as well as many other languages of the former Soviet Union, Asia and Eastern Europe.

### CkString.NumGreek

`Chilkat 11.7.0 · delphix · CkString · NumGreek · property · read-only · since 9.5.0.25`

```pascal
property NumGreek: Integer readonly
```

The number of Greek characters contained in this string.

### CkString.NumHebrew

`Chilkat 11.7.0 · delphix · CkString · NumHebrew · property · read-only · since 9.5.0.25`

```pascal
property NumHebrew: Integer readonly
```

The number of Hebrew characters contained in this string.

### CkString.NumJapanese

`Chilkat 11.7.0 · delphix · CkString · NumJapanese · property · read-only · since 9.5.0.25`

```pascal
property NumJapanese: Integer readonly
```

The number of Japanese characters contained in this string.

### CkString.NumKorean

`Chilkat 11.7.0 · delphix · CkString · NumKorean · property · read-only · since 9.5.0.25`

```pascal
property NumKorean: Integer readonly
```

The number of Korean characters contained in this string.

### CkString.NumLatin

`Chilkat 11.7.0 · delphix · CkString · NumLatin · property · read-only · since 9.5.0.25`

```pascal
property NumLatin: Integer readonly
```

The number of Latin characters contained in this string. Latin characters include all major Western European languages, such as German, Spanish, French, Italian, Nordic languages, etc.

**Note:** This is the number of chars that are Latin characters that do not fall in the us-ascii range. In other words, the 8bit Latin chars.

### CkString.NumThai

`Chilkat 11.7.0 · delphix · CkString · NumThai · property · read-only · since 9.5.0.25`

```pascal
property NumThai: Integer readonly
```

The number of Thai characters contained in this string.

### CkString.SizeAnsi

`Chilkat 11.7.0 · delphix · CkString · SizeAnsi · property · read-only`

```pascal
property SizeAnsi: Integer readonly
```

The size, in bytes, of the ANSI encoding of the string.

### CkString.SizeUtf8

`Chilkat 11.7.0 · delphix · CkString · SizeUtf8 · property · read-only`

```pascal
property SizeUtf8: Integer readonly
```

The size, in bytes, of the utf-8 encoding of the string.

### CkString.Str

`Chilkat 11.7.0 · delphix · CkString · Str · property · read/write`

```pascal
property Str: WideString
```

The string value of this object.

## Methods

### CkString.AnsiCharAt

`Chilkat 11.7.0 · delphix · CkString · AnsiCharAt · method`

```pascal
function AnsiCharAt(index: Integer): Integer;
```

Returns the ASCII value of the Nth char in the string. The 1st char is at index 0.

### CkString.Append

`Chilkat 11.7.0 · delphix · CkString · Append · method`

```pascal
procedure Append(str: WideString);
```

The `str` is appended to end of this instance.

### CkString.AppendEncoded

`Chilkat 11.7.0 · delphix · CkString · AppendEncoded · method`

```pascal
procedure AppendEncoded(str: WideString; encoding: WideString; charset: WideString);
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Appends characters from an encoded string. The encoding may be `base64`, `hex`, `url`, or `quoted-printable`. For example, to append `ABC 123` from a URL-encoded string, call:

```
strObj.AppendEncoded(ABC+123,url,iso-8859-1)
```

### CkString.AppendMultibyte

`Chilkat 11.7.0 · delphix · CkString · AppendMultibyte · method`

```pascal
procedure AppendMultibyte(mbtext: OleVariant; charsetEncoding: WideString);
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Appends characters from a byte array. `mbtext` contains the character data. The input bytes are interpreted according to the character encoding specified by `charsetEncoding`.

### CkString.AppendToFile

`Chilkat 11.7.0 · delphix · CkString · AppendToFile · method`

```pascal
function AppendToFile(path: WideString; charsetEncoding: WideString): Integer;
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Appends the contents of the string to a file. The string is first converted to the character encoding specified by `charsetEncoding` before being appended to the file.

### CkString.BeginsWith

`Chilkat 11.7.0 · delphix · CkString · BeginsWith · method`

```pascal
function BeginsWith(str: WideString): Integer;
```

Returns `1` if the string begins with `str`. Otherwise returns `0`. This method is case sensitive.

### CkString.ChopAfter

`Chilkat 11.7.0 · delphix · CkString · ChopAfter · method`

```pascal
procedure ChopAfter(findStr: WideString);
```

Truncates the string after the 1st occurrence of `findStr`. If `findStr` is not present, nothing is truncated.

### CkString.ChopBefore

`Chilkat 11.7.0 · delphix · CkString · ChopBefore · method`

```pascal
procedure ChopBefore(findStr: WideString);
```

Truncates the string before the 1st occurrence of `findStr`. If `findStr` is not present, nothing is truncated.

### CkString.Clear

`Chilkat 11.7.0 · delphix · CkString · Clear · method`

```pascal
procedure Clear();
```

Clears the string. After calling this method, the string contains 0 characters.

### CkString.Contains

`Chilkat 11.7.0 · delphix · CkString · Contains · method`

```pascal
function Contains(substr: WideString): Integer;
```

Returns `1` if `substr` is present in the string (case sensitive), otherwise returns `0`.

### CkString.EmitMultibyte

`Chilkat 11.7.0 · delphix · CkString · EmitMultibyte · method`

```pascal
function EmitMultibyte(charsetEncoding: WideString): OleVariant;
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Converts the string to a byte array using the character encoding specified by `charsetEncoding`.

Returns a zero-length byte array (as an OleVariant) on failure.  
An empty array will have a VarArrayHighBound of -1 meaning 0 elements.

### CkString.EndsWith

`Chilkat 11.7.0 · delphix · CkString · EndsWith · method`

```pascal
function EndsWith(substr: WideString): Integer;
```

Returns `1` if the string ends with `substr` (case-sensitive). Otherwise returns `0`.

### CkString.GetEncoded

`Chilkat 11.7.0 · delphix · CkString · GetEncoded · method`

```pascal
function GetEncoded(binaryEncoding: WideString; charsetEncoding: WideString): WideString;
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Returns the character string in an encoding use the `charsetEncoding` specified. The `binaryEncoding` may be `base64`, `hex`, `url`, or `quoted-printable`. For example:

```
(Visual Basic 6.0)

Dim s As New CkString

s.Str = Ã¨Ã¨Ã¨
Text1.Text = s.GetEncoded(hex, iso-8859-1) & vbCrLf
Text1.Text = Text.Text & s.GetEncoded(hex, utf-8) & vbCrLf
Text1.Text = Text1.Text & s.GetEncoded(hex, unicode)

'Output:
'E8E8E8
'C3A8C3A8C3A8
'E800E800E800
```

Returns a zero-length WideString on failure

### CkString.HtmlEntityDecode

`Chilkat 11.7.0 · delphix · CkString · HtmlEntityDecode · method`

```pascal
procedure HtmlEntityDecode();
```

Decodes any HTML entities found in the string.

### CkString.HtmlEntityEncode

`Chilkat 11.7.0 · delphix · CkString · HtmlEntityEncode · method`

```pascal
procedure HtmlEntityEncode();
```

HTML entity encodes all special characters. (Those characters that might require HTML entity encoding.)

### CkString.LastAnsiChar

`Chilkat 11.7.0 · delphix · CkString · LastAnsiChar · method`

```pascal
function LastAnsiChar(): Integer;
```

Returns the ASCII value of the last character in the string.

### CkString.Left

`Chilkat 11.7.0 · delphix · CkString · Left · method`

```pascal
function Left(numChars: Integer): WideString;
```

Returns a string that is the leftmost `numChars` of this instance.

Returns a zero-length WideString on failure

### CkString.Length

`Chilkat 11.7.0 · delphix · CkString · Length · method`

```pascal
function Length(): Integer;
```

Returns the length, in characters, of the string.

### CkString.LoadFile

`Chilkat 11.7.0 · delphix · CkString · LoadFile · method`

```pascal
function LoadFile(path: WideString; charsetEncoding: WideString): Integer;
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Loads an entire text file into the string object. The character encoding of the text file is specified by `charsetEncoding`. This method allows for text files in any charset to be loaded: utf-8, Unicode, Shift_JIS, iso-8859-1, etc.

### CkString.LoadXmlDoc

`Chilkat 11.7.0 · delphix · CkString · LoadXmlDoc · method`

```pascal
procedure LoadXmlDoc(xmlDocumentBytes: OleVariant);
```

Loads an XML document into the CkString. The `xmlDocumentBytes` contains the raw bytes of the XML document. The reason for providing a separate method for loading an XML document is because the charset encoding is usually specified using a `charset` attribute at the beginning of the XML document. The LoadXmlDoc method reads just enough of the XML document to get the charset, and then it knows how to read and interpret the bytes of the entire XML document, so that the bytes of the characters are properly interpeted and loaded into the CkString object.

### CkString.Matches

`Chilkat 11.7.0 · delphix · CkString · Matches · method`

```pascal
function Matches(strPattern: WideString; caseSensitive: Integer): Integer;
```

Returns `1` if the string matches the `strPattern`, which may contain one or more asterisk wildcard characters. Case-sensitivity is controlled by , where 1 = case sensitive, 0 = case insensitive.

### CkString.Mid

`Chilkat 11.7.0 · delphix · CkString · Mid · method`

```pascal
function Mid(index: Integer; numChars: Integer): WideString;
```

Same as the VB/VBScript `Mid` function, except that the 1st char is at index 0 (i.e. it is not 1-based). Returns a substring of length `numChars` starting at `index`.

Returns a zero-length WideString on failure

### CkString.Pluralize

`Chilkat 11.7.0 · delphix · CkString · Pluralize · method`

```pascal
procedure Pluralize();
```

Pluralizes an English word.

### CkString.Prepend

`Chilkat 11.7.0 · delphix · CkString · Prepend · method`

```pascal
procedure Prepend(str: WideString);
```

Prepends `str` to this instance.

### CkString.PunyDecode

`Chilkat 11.7.0 · delphix · CkString · PunyDecode · method · since 9.5.0.52`

```pascal
procedure PunyDecode();
```

In-place decodes the string from punycode.

### CkString.PunyEncode

`Chilkat 11.7.0 · delphix · CkString · PunyEncode · method · since 9.5.0.52`

```pascal
procedure PunyEncode();
```

In-place encodes the string to punycode.

### CkString.RemoveAnsiChar

`Chilkat 11.7.0 · delphix · CkString · RemoveAnsiChar · method`

```pascal
procedure RemoveAnsiChar(ch: Integer);
```

Removes all occurrences of `ch` from the string.

### CkString.ReplaceAll

`Chilkat 11.7.0 · delphix · CkString · ReplaceAll · method`

```pascal
procedure ReplaceAll(findStr: WideString; replaceStr: WideString);
```

Replaces all occurrences of `findStr` with `replaceStr`. (case sensitive)

### CkString.ReplaceAnsiChar

`Chilkat 11.7.0 · delphix · CkString · ReplaceAnsiChar · method`

```pascal
procedure ReplaceAnsiChar(findCh: Integer; replaceCh: Integer);
```

Replaces all occurrences of `findCh` with `replaceCh`.

### CkString.ReplaceFirst

`Chilkat 11.7.0 · delphix · CkString · ReplaceFirst · method`

```pascal
procedure ReplaceFirst(findStr: WideString; replaceStr: WideString);
```

Replaces the first occurrence of `findStr` with `replaceStr`. (case sensitive)

### CkString.Right

`Chilkat 11.7.0 · delphix · CkString · Right · method`

```pascal
function Right(numChars: Integer): WideString;
```

Returns a string that is the rightmost `numChars` of this instance.

Returns a zero-length WideString on failure

### CkString.SaveToFile

`Chilkat 11.7.0 · delphix · CkString · SaveToFile · method`

```pascal
function SaveToFile(path: WideString; charsetEncoding: WideString): Integer;
```

**Full documentation for this method (same in every language):** [Supported Character Encodings](https://www.chilkatsoft.com/ai-docs/v/11.7.0/articles/charsets_supported_by_chilkat.md)

Saves the string to a file, using the character encoding specified by `charsetEncoding`. This method allows for the string to be saved using character encodings such as `utf-8`, `Unicode`, `Shift-JIS`, or anything else...

Returns 1 for success, 0 for failure.

### CkString.Shorten

`Chilkat 11.7.0 · delphix · CkString · Shorten · method`

```pascal
procedure Shorten(numChars: Integer);
```

Removes the final `numChars` from the string.

### CkString.StrComp

`Chilkat 11.7.0 · delphix · CkString · StrComp · method`

```pascal
function StrComp(str: WideString; caseSensitive: Integer): Integer;
```

Lexicographically compares two strings. Returns 0 if both strings are equal. A value greater than zero indicates that the first character that does not match has a greater value in the caller's string than in `str`; And a value less than zero indicates the opposite.

### CkString.StripHtml

`Chilkat 11.7.0 · delphix · CkString · StripHtml · method`

```pascal
procedure StripHtml();
```

Strips HTML tags from a string.

### CkString.ToCRLF

`Chilkat 11.7.0 · delphix · CkString · ToCRLF · method`

```pascal
procedure ToCRLF();
```

Converts all line endings to CRLF.

### CkString.ToLF

`Chilkat 11.7.0 · delphix · CkString · ToLF · method`

```pascal
procedure ToLF();
```

Converts all line endings to bare-LF (Unix/Linux style).

### CkString.Trim

`Chilkat 11.7.0 · delphix · CkString · Trim · method`

```pascal
procedure Trim();
```

Trim SPACE and Tab characters from both ends of the string.

### CkString.Trim2

`Chilkat 11.7.0 · delphix · CkString · Trim2 · method`

```pascal
procedure Trim2();
```

Trim SPACE, Tab, CR, and LF characters from both ends of the string.

### CkString.TrimInside

`Chilkat 11.7.0 · delphix · CkString · TrimInside · method`

```pascal
procedure TrimInside();
```

Replaces all tabs, CR's, and LF's, with SPACE chars, and removes extra SPACE's so there are no occurrences of more than one SPACE char in a row.

### CkString.Unpluralize

`Chilkat 11.7.0 · delphix · CkString · Unpluralize · method`

```pascal
procedure Unpluralize();
```

Unpluralizes an English word.

