# TextUtils

Namespace: **Wisej.Base**

Assembly: **Wisej.Framework** (4.0.0.0)

Provides utility methods to measure, encode, and extract mnemonics from text.

{% tabs %}
{% tab title="C#" %}

```csharp
public class TextUtils
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class TextUtils
```

{% endtab %}
{% endtabs %}

## Fields

| Name                | Type                                                                                                  | Description                                                                                                                             |
| ------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **ConvertToString** | [Func\<Object, Object, String>](https://docs.microsoft.com/dotnet/api/system.func-3)                  | <p>Pluggable method used to convert user input to a string.<br><mark style="color:blue;background-color:green;">Since 3.0.10</mark></p> |
| **MeasureString**   | [Func\<String, Font, Size, StringFormat, SizeF>](https://docs.microsoft.com/dotnet/api/system.func-5) | Pluggable method used to measure strings.                                                                                               |

## Methods

### ![](/files/lIX317sDtMTZJBi9oSIx) EscapeText(text, allowHtml)

Escapes special characters in the specified string.

| Parameter                                      | Type                                                            | Description                                                           |
| ---------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------- |
| **text**                                       | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The text to escape.                                                   |
| **allowHtml** ![](/files/1vGqtbG2j637vQ4ROWOf) | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Indicates that HTML tags should not be escaped. The default is false. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The escaped string. Null if the specified string was null, or empty if it was empty.

### ![](/files/lIX317sDtMTZJBi9oSIx) EscapeText(text, allowHtml, useMnemonic, translateNewLines)

Removes the ampersand from the text and encodes HTML characters if necessary.

| Parameter             | Type                                                            | Description                                                                                                                                                                          |
| --------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **text**              | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The text to convert.                                                                                                                                                                 |
| **allowHtml**         | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Whether to encode HTML characters.                                                                                                                                                   |
| **useMnemonic**       | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Whether to convert the first mnemonic to an underlined character.                                                                                                                    |
| **translateNewLines** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | <p>Whether to convert newlines (CRLF) to \<BR/>. The conversion is performed only when<br>allowHtml is false, or, if<br>allowHtml is true and the text doesn't contain any HTML.</p> |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The escaped string. Null if the specified string was null, or empty if it was empty.

### ![](/files/lIX317sDtMTZJBi9oSIx) GetMnemonic(text)

Returns the first character that is preceded by an ampersand (&).

| Parameter | Type                                                          | Description                                              |
| --------- | ------------------------------------------------------------- | -------------------------------------------------------- |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The string from which to extract the mnemonic character. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string).

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, font)

Returns the size of the specified text when rendered with the specified font.

| Parameter | Type                                                              | Description                                                                                          |
| --------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The text to measure.                                                                                 |
| **font**  | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text. |

**Returns:** [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size). The computed [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size) of the specified text.

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, font, format)

Returns the size of the specified text when rendered with the specified font.

| Parameter  | Type                                                                              | Description                                                                                          |
| ---------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **text**   | [String](https://docs.microsoft.com/dotnet/api/system.string)                     | The text to measure.                                                                                 |
| **font**   | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font)                 | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text. |
| **format** | [StringFormat](https://docs.microsoft.com/dotnet/api/system.drawing.stringformat) | Formatting information.                                                                              |

**Returns:** [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size). The computed [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size) of the specified text.

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, font, layoutArea)

Returns the size of the specified text when rendered with the specified font.

| Parameter      | Type                                                              | Description                                                                                                      |
| -------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| **text**       | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The text to measure.                                                                                             |
| **font**       | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text.             |
| **layoutArea** | [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size) | The [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size) to use as bounding rectangle for the text. |

**Returns:** [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size).

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, font, layoutArea, format)

Returns the size of the specified text when rendered with the specified font.

| Parameter      | Type                                                                              | Description                                                                                                      |
| -------------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| **text**       | [String](https://docs.microsoft.com/dotnet/api/system.string)                     | The text to measure.                                                                                             |
| **font**       | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font)                 | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text.             |
| **layoutArea** | [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size)                 | The [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size) to use as bounding rectangle for the text. |
| **format**     | [StringFormat](https://docs.microsoft.com/dotnet/api/system.drawing.stringformat) | Formatting information.                                                                                          |

**Returns:** [Size](https://docs.microsoft.com/dotnet/api/system.drawing.size).

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, allowHtml, font, callback)

Returns the size of the specified text when rendered with the specified font.

| Parameter     | Type                                                                   | Description                                                                                          |
| ------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **text**      | [String](https://docs.microsoft.com/dotnet/api/system.string)          | The text to measure.                                                                                 |
| **allowHtml** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)        | The text to measure may contain HTML tags.                                                           |
| **font**      | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font)      | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text. |
| **callback**  | [Action\<Size>](https://docs.microsoft.com/dotnet/api/system.action-1) | Result callback method, invoked when the client has finished measuring the text.                     |

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureText(text, allowHtml, font, width, callback)

Returns the size of the specified text when rendered with the specified font.

| Parameter     | Type                                                                   | Description                                                                                          |
| ------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **text**      | [String](https://docs.microsoft.com/dotnet/api/system.string)          | The text to measure.                                                                                 |
| **allowHtml** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)        | The text to measure may contain HTML tags.                                                           |
| **font**      | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font)      | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text. |
| **width**     | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)            | The width to use as bounding rectangle for the text.                                                 |
| **callback**  | [Action\<Size>](https://docs.microsoft.com/dotnet/api/system.action-1) | Result callback method, invoked when the client has finished measuring the text.                     |

### ![](/files/lIX317sDtMTZJBi9oSIx) MeasureTextAsync(text, allowHtml, font, width)

Asynchronously returns the size of the specified text when rendered with the specified font. The measurement is performed on the browser. Returns an awaitable [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task) that contains the measured size.

| Parameter                                  | Type                                                              | Description                                                                                          |
| ------------------------------------------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **text**                                   | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The text to measure.                                                                                 |
| **allowHtml**                              | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)   | The text to measure may contain HTML tags.                                                           |
| **font**                                   | [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) | The [Font](https://docs.microsoft.com/dotnet/api/system.drawing.font) to apply to the measured text. |
| **width** ![](/files/1vGqtbG2j637vQ4ROWOf) | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)       | The optional width to use as bounding rectangle for the text.                                        |

**Returns:** [Task\<Size>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). An awaitable [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task) that represents the asynchronous operation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.base/general/wisej.base.textutils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
