# Whitespace Handling

AndHow generally removes leading and trailing whitespace from values as they are loaded, and each Property has a `Trimmer` instance to do the trimming.

Depending on where values are loaded from (i.e. which loader is used) trimming of String type values maybe enabled or disabled. For instance, if a String value is loaded from JNDI (the StdJndiLoader) or as a fixed value in code (StdFixedValueLoader), no trimming is done for String values because it is assumed that the value is in its final form. Non-String values are always trimmed as they are loaded.

### Non-String Property Trimming

The `TrimToNullTrimmer` is used by most non-text properties and simply removes all whitespace on either end of a value. If the result is a zero length string, it becomes null.

### String Property Trimming

`StrProp`, and likely most other text based properties, use a special `QuotedSpacePreservingTrimmer` (QSPT). The *QSPT* first trims to null, then, if the remaining text begins and ends with double quotes, those quotes are removed and the string inside the quotes, including whitespace, is preserved as the actual value.

Here are a few examples of the *QSPT* trimming behavior, using dots (**●**)to represent whitespace and -> to separate the raw value on the left from the trimmed value on the right:

| Raw Value           | QSPT Trimmed Value | Notes                                                                          |
| ------------------- | ------------------ | ------------------------------------------------------------------------------ |
| **●**               | \[null]            | An all whitespace raw value is trimmed to null                                 |
| ●●●abc●●●           | abc                | whitespace on either side of text removed                                      |
| "●abc●"             | ●abc●              | Quotes are removed and all characters inside preserved                         |
| ●"●abc●"●           | ●abc●              | same result - whitespace outside the quotes is removed                         |
| ●a "word" here●     | a "word" here      | No special quote handling here - there is text outside the quotes              |
| ●"●a "word" here●"● | ●a "word" here●    | After trimming outer whitespace, leading and trailing double quotes were found |
| ●""●                | \[empty string]    | Using quotes, it is possible to assign an empty string                         |

The trimmer for a Property can be changed if a different behaviour is needed:

```java
StrProp TRIM_ME_TO_NULL =
    StrProp.builder.trimmer(TrimToNullTrimmer.instance()).build();
```


---

# 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://www.andhowconfig.org/user-guide/whitespace-handling.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.
