# Shrink()

Optionally, an alternative replacement can be specified.  In addition, the trimming can be disabled.

{% hint style="info" %}
Included since 📦**v1.2.0**
{% endhint %}

#### **Underlying Idea**

:bulb: This method was inspired by a *heat shrink*. As it contracts, it pushes out the air (i.e. the whitespace) around the edges and applies pressure compressing the air within.

#### **Cute Illustration**

`👻🌴🌴👻☁️👻🌳🌳🌳☁️☁️` → `🌴🌴👻🌳🌳🌳`

#### **Example**

<pre class="language-csharp"><code class="lang-csharp">// Suppose we have a string variable containing whitespace.
var myString = "··foo···bar\n";

// By default, the string is trimmed and remaining whitespace
// is replaced with a single space.
var shrunkString_Default = myString.Shrink();
// Value of 'shrunkString_Default' is "foo·bar" now.

// Alternatively, you can specify your own replacement char.
var shrunkString_CustomReplacement = myString.Shrink('-');
// Value of 'shrunkString_CustomReplacement' is "foo-bar" now.

// Additionally, trimming can be disabled.
var shrunkString_NotTrimmed = myString.Shrink('-', false);
// Value of 'shrunkString_NotTrimmed' is "-foo-bar-" now.

<strong>// In each case, the original 'myString' variable remains unchanged.
</strong></code></pre>

#### **Equivalent to**

```csharp
var shrunkString_Default = Regex.Replace(myString.Trim(), @"\s+", " ");
```


---

# 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://mx-pl.gitbook.io/extendedtypes-docs/string/shrink.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.
