# SquashWhiteSpace()

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

#### Cute Illustration

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

#### **Example**

```csharp
// Suppose we have a string variable containing whitespace.
var myString = "foo···bar\n";

// By default, whitespace is replaced with a single space.
var squashedString_Default = myString.SquashWhiteSpace();
// Value of 'squashedString_Default' is "foo·bar·" now.

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

// If the replacement is set to 'null', whitespace is removed entirely.
var squashedString_ReplacementIsNull = myString.SquashWhiteSpace(null);
// Value of 'squashedString_ReplacementIsNull' is "foobar" now.

// In each case, the original 'myString' variable remains unchanged.
```

#### **Equivalent to**

```csharp
var squashedString_Default = Regex.Replace(myString, @"\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/squashwhitespace.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.
