> For the complete documentation index, see [llms.txt](https://wrapper.angular-package.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wrapper.angular-package.dev/wrap/methods/instance/replacetext.md).

# ★ replaceText()

## `Wrap.prototype.replaceText()`

Returns the [primitive value](/wrap/methods/instance/valueof.md) with replaced [`text`](/wrap/accessors/text.md).

{% code title="wrap.class.ts" %}

```typescript
public replaceText<ReplaceText extends string = ''>(
  text: ReplaceText
): `${Opening}${ReplaceText}${Closing}` {
  return `${this.#opening}${text}${this.#closing}`;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">**`ReplaceText`**</mark>**`extends`**<mark style="color:green;">**`string`**</mark>**`=`**<mark style="color:green;">**`''`**</mark>

A generic type variable constrained by the [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string), by default of the value captured from the provided [`text`](#text-replacetext) indicates the `ReplaceText` type on the template of the [return type](#return-type).

### Parameters

#### `text: ReplaceText`

The text of a generic type variable [`ReplaceText`](#replacetext-extends-string) to replace the [`text`](/wrap/accessors/text.md) in the [primitive value](/wrap/methods/instance/valueof.md).

### Return type

#### `${Opening}${ReplaceText}${Closing}`

The **return type** is the [template literal](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) of generic type variables in order [`Opening`](/wrap/generic-type-variables.md#wrap-opening), [`ReplaceText`](#replacetextextendsstring) and [`Closing`](/wrap/generic-type-variables.md#wrap-closing).&#x20;

### Returns

The **return value** is the [primitive value](/wrap/methods/instance/valueof.md) with replaced [`text`](/wrap/accessors/text.md) of a generic type variables in order [`Opening`](/wrap/generic-type-variables.md#wrap-opening), [`ReplaceText`](#replacetextextendsstring) and [`Closing`](/wrap/generic-type-variables.md#wrap-closing) on the template.

## Example usage

```typescript
// Example usage.
import { Wrap } from '@angular-package/wrapper';

// Returns [span] of type "[span]".
new Wrap(`[`, `]`, 'quote').replaceText('span');

// Returns [bold] of "[bold]".
new Wrap(`[`, `]`, '').replaceText('bold');

// Returns [u] of "[u]".
new Wrap(`[`, `]`).replaceText('u');

// Returns size] of "size]".
new Wrap(``, `]`).replaceText('size');

// Returns [size of "[size".
new Wrap(`[`, ``).replaceText('size');
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://wrapper.angular-package.dev/wrap/methods/instance/replacetext.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.
