---
product: Chilkat
product_version: 11.7.0
language: csharp
language_label: C#
class: CkString
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/csCkStringRef.html
---
# Chilkat CkString — C# — v11.7.0

> Chilkat 11.7.0 · language=csharp · class=CkString
> 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/csharp/guide.md`.

## Purpose

The Chilkat string class.

## Object creation, unlocking and error handling

**Object Creation**

```csharp
Chilkat.CkString obj = new Chilkat.CkString();
```

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 C#.

Minimal complete program:

```csharp
// Required once per process. Any string unlocks a 30-day trial; use your purchased code in production.
Chilkat.Global glob = new Chilkat.Global();
if (!glob.UnlockBundle("Anything for 30-day trial"))
{
    Console.WriteLine(glob.LastErrorText);
    return;
}

Chilkat.CkString ckString = new Chilkat.CkString();

bool success = ckString.loadFile("<path>", "<charsetEncoding>");
if (!success)
{
    Console.WriteLine(ckString.LastErrorText);   // full diagnostic of what went wrong
    return;
}
```

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 |
|---|---|---|
| `append` | method | `public void append(string str);` |
| `appendInt` | method | `public void appendInt(int n);` |
| `appendObfuscated` | method | `public void appendObfuscated(string obfuscatedStr);` |
| `autoLinkUrls` | method | `public void autoLinkUrls();` |
| `base64Decode` | method | `public void base64Decode(string charsetEncoding);` |
| `base64Encode` | method | `public void base64Encode(string charsetEncoding);` |
| `beginsWith` | method | `public bool beginsWith(string substr);` |
| `charAt` | method | `public char charAt(int idx);` |
| `chopAtFirstChar` | method | `public void chopAtFirstChar(char ch);` |
| `clear` | method | `public void clear();` |
| `containsSubstring` | method | `public bool containsSubstring(string substr);` |
| `containsSubstringNoCase` | method | `public bool containsSubstringNoCase(string substr);` |
| `decodeXMLSpecial` | method | `public void decodeXMLSpecial();` |
| `doubleValue` | method | `public double doubleValue();` |
| `eliminateChar` | method | `public void eliminateChar(char ansiChar, int startIndex);` |
| `encodeXMLSpecial` | method | `public void encodeXMLSpecial();` |
| `entityDecode` | method | `public void entityDecode();` |
| `entityEncode` | method | `public void entityEncode();` |
| `equals` | method | `public bool equals(string str);` |
| `equalsIgnoreCase` | method | `public bool equalsIgnoreCase(string str);` |
| `getNumChars` | method | `public int getNumChars();` |
| `getSizeAnsi` | method | `public int getSizeAnsi();` |
| `getSizeUnicode` | method | `public int getSizeUnicode();` |
| `getSizeUtf8` | method | `public int getSizeUtf8();` |
| `getString` | method | `public mbString getString();` |
| `hexDecode` | method | `public void hexDecode(string charsetEncoding);` |
| `hexEncode` | method | `public void hexEncode(string charsetEncoding);` |
| `intValue` | method | `public int intValue();` |
| `loadFile` | method | `public bool loadFile(string path, string charsetEncoding);` |
| `loadXmlFile` | method | `public bool loadXmlFile(string path);` |
| `obfuscate` | method | `public void obfuscate();` |
| `prepend` | method | `public void prepend(string str);` |
| `punyDecode` | method | `public void punyDecode();` |
| `punyEncode` | method | `public void punyEncode();` |
| `qpDecode` | method | `public void qpDecode(string charsetEncoding);` |
| `qpEncode` | method | `public void qpEncode(string charsetEncoding);` |
| `removeCharOccurances` | method | `public void removeCharOccurances(char ch);` |
| `removeChunk` | method | `public void removeChunk(int charStartPos, int numChars);` |
| `removeDelimited` | method | `public void removeDelimited(string beginDelim, string endDelim, bool caseSensitive);` |
| `replaceAllOccurances` | method | `public int replaceAllOccurances(string findStr, string replaceStr);` |
| `replaceChar` | method | `public void replaceChar(char findCh, char replaceCh);` |
| `replaceFirstOccurance` | method | `public bool replaceFirstOccurance(string findStr, string replaceStr);` |
| `saveToFile` | method | `public bool saveToFile(string path, string charsetEncoding);` |
| `setString` | method | `public void setString(string str);` |
| `shorten` | method | `public void shorten(int n);` |
| `toCRLF` | method | `public void toCRLF();` |
| `toLF` | method | `public void toLF();` |
| `toLowerCase` | method | `public void toLowerCase();` |
| `toUpperCase` | method | `public void toUpperCase();` |
| `trim` | method | `public void trim();` |
| `trim2` | method | `public void trim2();` |
| `trimInsideSpaces` | method | `public void trimInsideSpaces();` |
| `unobfuscate` | method | `public void unobfuscate();` |
| `urlDecode` | method | `public void urlDecode(string charsetEncoding);` |
| `urlEncode` | method | `public void urlEncode(string charsetEncoding);` |

## Methods

### CkString.append

`Chilkat 11.7.0 · csharp · CkString · append · method`

```csharp
public void append(string str);
```

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

### CkString.appendInt

`Chilkat 11.7.0 · csharp · CkString · appendInt · method`

```csharp
public void appendInt(int n);
```

Appends the decimal string representation of an integer to the end of this instance.

### CkString.appendObfuscated

`Chilkat 11.7.0 · csharp · CkString · appendObfuscated · method`

```csharp
public void appendObfuscated(string obfuscatedStr);
```

Unobfuscates and appends `obfuscatedStr` to the end of this instance.

The Chilkat string obfuscation algorithm works by taking the utf-8 bytes of the string, base64 encoding it, and then scrambling the letters of the base64 encoded string. It is deterministic in that the same string will always obfuscate to the same result. It is not a secure way of encrypting a string. It is only meant to be a simple means of transforming a string into something unintelligible.

### CkString.autoLinkUrls

`Chilkat 11.7.0 · csharp · CkString · autoLinkUrls · method`

```csharp
public void autoLinkUrls();
```

Convert URLs into HTML hyperlinks, using the URL itself as the link text.

### CkString.base64Decode

`Chilkat 11.7.0 · csharp · CkString · base64Decode · method`

```csharp
public void base64Decode(string charsetEncoding);
```

**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)

In-place base64 decodes the string and inteprets the results according to the character encoding specified.

### CkString.base64Encode

`Chilkat 11.7.0 · csharp · CkString · base64Encode · method`

```csharp
public void base64Encode(string charsetEncoding);
```

**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)

In-place base64 encodes the string. Internally, the string is first converted to the character encoding specified and then base-64 encoded. Typical `charsetEncoding` values are `utf-8`, `ANSI`, `iso-8859-1`, etc.

### CkString.beginsWith

`Chilkat 11.7.0 · csharp · CkString · beginsWith · method`

```csharp
public bool beginsWith(string substr);
```

Return `true` if this string begins with `substr` (case sensitive), otherwise returns `false`.

### CkString.charAt

`Chilkat 11.7.0 · csharp · CkString · charAt · method`

```csharp
public char charAt(int idx);
```

Returns the ANSI character at a specified index.The first character is at index 0.

### CkString.chopAtFirstChar

`Chilkat 11.7.0 · csharp · CkString · chopAtFirstChar · method`

```csharp
public void chopAtFirstChar(char ch);
```

Finds the first occurrence of `ch` and discards the characters at and following `ch`.

### CkString.clear

`Chilkat 11.7.0 · csharp · CkString · clear · method`

```csharp
public void clear();
```

Clears the string. The string contains 0 characters after calling this method.

### CkString.containsSubstring

`Chilkat 11.7.0 · csharp · CkString · containsSubstring · method`

```csharp
public bool containsSubstring(string substr);
```

Returns `true` if the string contains the specified substring, otherwise returns `false`. The string comparison is case-sensitive.

### CkString.containsSubstringNoCase

`Chilkat 11.7.0 · csharp · CkString · containsSubstringNoCase · method`

```csharp
public bool containsSubstringNoCase(string substr);
```

Same as containsSubstring except the matching is case insensitive.

### CkString.decodeXMLSpecial

`Chilkat 11.7.0 · csharp · CkString · decodeXMLSpecial · method`

```csharp
public void decodeXMLSpecial();
```

Decodes XML special characters. For example, < is converted to '<'

### CkString.doubleValue

`Chilkat 11.7.0 · csharp · CkString · doubleValue · method`

```csharp
public double doubleValue();
```

Converts the string to a double and returns the value.

### CkString.eliminateChar

`Chilkat 11.7.0 · csharp · CkString · eliminateChar · method`

```csharp
public void eliminateChar(char ansiChar, int startIndex);
```

Eliminate all occurrences of a particular ANSI character.

### CkString.encodeXMLSpecial

`Chilkat 11.7.0 · csharp · CkString · encodeXMLSpecial · method`

```csharp
public void encodeXMLSpecial();
```

Encodes XML special characters. For example, '<' is converted to <

### CkString.entityDecode

`Chilkat 11.7.0 · csharp · CkString · entityDecode · method`

```csharp
public void entityDecode();
```

Decodes any HTML entities found within the string, replacing them with the characters represented.

### CkString.entityEncode

`Chilkat 11.7.0 · csharp · CkString · entityEncode · method`

```csharp
public void entityEncode();
```

HTML encodes any characters that are special to HTML or cannot be represented by 7-bit us-ascii.

### CkString.equals

`Chilkat 11.7.0 · csharp · CkString · equals · method`

```csharp
public bool equals(string str);
```

Returns `true` if the strings are equal, otherwise returns `false`. (case-sensitive)

### CkString.equalsIgnoreCase

`Chilkat 11.7.0 · csharp · CkString · equalsIgnoreCase · method`

```csharp
public bool equalsIgnoreCase(string str);
```

Returns `true` if the strings are equal, otherwise returns `false`. (case-insensitive)

### CkString.getNumChars

`Chilkat 11.7.0 · csharp · CkString · getNumChars · method`

```csharp
public int getNumChars();
```

Returns the number of characters in the string.

### CkString.getSizeAnsi

`Chilkat 11.7.0 · csharp · CkString · getSizeAnsi · method`

```csharp
public int getSizeAnsi();
```

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

### CkString.getSizeUnicode

`Chilkat 11.7.0 · csharp · CkString · getSizeUnicode · method`

```csharp
public int getSizeUnicode();
```

Returns the size, in bytes, of the Unicode encoding of the string.

### CkString.getSizeUtf8

`Chilkat 11.7.0 · csharp · CkString · getSizeUtf8 · method`

```csharp
public int getSizeUtf8();
```

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

### CkString.getString

`Chilkat 11.7.0 · csharp · CkString · getString · method`

```csharp
public mbString getString();
```

Returns the contents of this instance.

### CkString.hexDecode

`Chilkat 11.7.0 · csharp · CkString · hexDecode · method`

```csharp
public void hexDecode(string charsetEncoding);
```

**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)

Hex decodes a string and inteprets the bytes according to the character encoding specified.

### CkString.hexEncode

`Chilkat 11.7.0 · csharp · CkString · hexEncode · method`

```csharp
public void hexEncode(string charsetEncoding);
```

**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 the character encoding specified and replaces the string contents with the hex encoding of the character data.

### CkString.intValue

`Chilkat 11.7.0 · csharp · CkString · intValue · method`

```csharp
public int intValue();
```

Converts the string to an integer and returns the integer value.

### CkString.loadFile

`Chilkat 11.7.0 · csharp · CkString · loadFile · method`

```csharp
public bool loadFile(string path, string charsetEncoding);
```

**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)

Load the contents of a text file into the CkString object. The string is cleared before loading. 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.

Returns true for success, false for failure.

### CkString.loadXmlFile

`Chilkat 11.7.0 · csharp · CkString · loadXmlFile · method`

```csharp
public bool loadXmlFile(string path);
```

Loads an XML document into the CkString. 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 LoadXmlFile 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.

Returns true for success, false for failure.

### CkString.obfuscate

`Chilkat 11.7.0 · csharp · CkString · obfuscate · method`

```csharp
public void obfuscate();
```

Obfuscates the string. (The unobfuscate method can be called to reverse the obfuscation to restore the original string.)

The Chilkat string obfuscation algorithm works by taking the utf-8 bytes of the string, base64 encoding it, and then scrambling the letters of the base64 encoded string. It is deterministic in that the same string will always obfuscate to the same result. It is not a secure way of encrypting a string. It is only meant to be a simple means of transforming a string into something unintelligible.

### CkString.prepend

`Chilkat 11.7.0 · csharp · CkString · prepend · method`

```csharp
public void prepend(string str);
```

Prepends `str` to this instance.

### CkString.punyDecode

`Chilkat 11.7.0 · csharp · CkString · punyDecode · method · since 9.5.0.52`

```csharp
public void punyDecode();
```

In-place decodes the string from punycode.

### CkString.punyEncode

`Chilkat 11.7.0 · csharp · CkString · punyEncode · method · since 9.5.0.52`

```csharp
public void punyEncode();
```

In-place encodes the string to punycode.

### CkString.qpDecode

`Chilkat 11.7.0 · csharp · CkString · qpDecode · method`

```csharp
public void qpDecode(string charsetEncoding);
```

**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)

Quoted-printable decodes the string and interprets the resulting character data according to the specified character encoding. The result is that the quoted-printable string is in-place decoded.

### CkString.qpEncode

`Chilkat 11.7.0 · csharp · CkString · qpEncode · method`

```csharp
public void qpEncode(string charsetEncoding);
```

**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)

Quoted-printable encodes the string. The string is first converted to the charset specified, and those bytes are QP-encoded. The contents of the string are replaced with the QP-encoded result.

### CkString.removeCharOccurances

`Chilkat 11.7.0 · csharp · CkString · removeCharOccurances · method`

```csharp
public void removeCharOccurances(char ch);
```

Removes all occurrences of a specific ANSI character from the string.

### CkString.removeChunk

`Chilkat 11.7.0 · csharp · CkString · removeChunk · method`

```csharp
public void removeChunk(int charStartPos, int numChars);
```

Removes a chunk of characters specified by starting index and length.

### CkString.removeDelimited

`Chilkat 11.7.0 · csharp · CkString · removeDelimited · method · since 9.5.0.52`

```csharp
public void removeDelimited(string beginDelim, string endDelim, bool caseSensitive);
```

Remove all occurrences of strings delimited by `beginDelim` and `endDelim`. Also removes the delimiters.

### CkString.replaceAllOccurances

`Chilkat 11.7.0 · csharp · CkString · replaceAllOccurances · method`

```csharp
public int replaceAllOccurances(string findStr, string replaceStr);
```

Replaces all occurrences of a substring with another substring. The replacement string is allowed to be empty or different in length.

### CkString.replaceChar

`Chilkat 11.7.0 · csharp · CkString · replaceChar · method`

```csharp
public void replaceChar(char findCh, char replaceCh);
```

Replaces all occurrences of a specified ANSI character with another.

### CkString.replaceFirstOccurance

`Chilkat 11.7.0 · csharp · CkString · replaceFirstOccurance · method`

```csharp
public bool replaceFirstOccurance(string findStr, string replaceStr);
```

Replaces the first occurrence of a substring with another. The replacement string is allowed to be empty or different in length. (Chilkat is aware of the misspelling of the word `occurrence`, but unfortunately it is too late to change..)

### CkString.saveToFile

`Chilkat 11.7.0 · csharp · CkString · saveToFile · method`

```csharp
public bool saveToFile(string path, string charsetEncoding);
```

**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`. If a file of the same name exists, it is overwritten. For charsets such as `utf-8`, `utf-16`, or others that have a possible BOM/preamble, the preamble is output by default. To exclude the BOM/preamble, prepend `no-bom-` to the charset name. For example `no-bom-utf-8`.

Returns true for success, false for failure.

### CkString.setString

`Chilkat 11.7.0 · csharp · CkString · setString · method`

```csharp
public void setString(string str);
```

Clears the contents of this instance and appends `str`.

### CkString.shorten

`Chilkat 11.7.0 · csharp · CkString · shorten · method`

```csharp
public void shorten(int n);
```

Discards the last N characters.

### CkString.toCRLF

`Chilkat 11.7.0 · csharp · CkString · toCRLF · method`

```csharp
public void toCRLF();
```

Converts all line endings to CRLF.

### CkString.toLF

`Chilkat 11.7.0 · csharp · CkString · toLF · method`

```csharp
public void toLF();
```

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

### CkString.toLowerCase

`Chilkat 11.7.0 · csharp · CkString · toLowerCase · method`

```csharp
public void toLowerCase();
```

Converts the string to lowercase.

### CkString.toUpperCase

`Chilkat 11.7.0 · csharp · CkString · toUpperCase · method`

```csharp
public void toUpperCase();
```

Converts the string to uppercase.

### CkString.trim

`Chilkat 11.7.0 · csharp · CkString · trim · method`

```csharp
public void trim();
```

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

### CkString.trim2

`Chilkat 11.7.0 · csharp · CkString · trim2 · method`

```csharp
public void trim2();
```

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

### CkString.trimInsideSpaces

`Chilkat 11.7.0 · csharp · CkString · trimInsideSpaces · method`

```csharp
public void trimInsideSpaces();
```

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.unobfuscate

`Chilkat 11.7.0 · csharp · CkString · unobfuscate · method`

```csharp
public void unobfuscate();
```

Unobfuscates the string.

The Chilkat string obfuscation algorithm works by taking the utf-8 bytes of the string, base64 encoding it, and then scrambling the letters of the base64 encoded string. It is deterministic in that the same string will always obfuscate to the same result. It is not a secure way of encrypting a string. It is only meant to be a simple means of transforming a string into something unintelligible.

### CkString.urlDecode

`Chilkat 11.7.0 · csharp · CkString · urlDecode · method`

```csharp
public void urlDecode(string charsetEncoding);
```

**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)

URL decodes the string and interprets the resulting byte data in the specified charset encoding.

### CkString.urlEncode

`Chilkat 11.7.0 · csharp · CkString · urlEncode · method`

```csharp
public void urlEncode(string charsetEncoding);
```

**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)

URL encodes the string. The string is first converted to the specified charset encoding, and those bytes are URL-encoded. The contents of the string are replaced with the URL-encoded result.

