> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/services/itextsplitterservice/wisej.ai.services.textsplitterservicebase.md).

# TextSplitterServiceBase

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Provides the base functionality for text splitting services, allowing subclasses to define custom splitting logic.

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

```csharp
public class TextSplitterServiceBase : ITextSplitterService
```

{% endtab %}

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

```visual-basic
Public Class TextSplitterServiceBase
    Inherits ITextSplitterService
```

{% endtab %}
{% endtabs %}

This abstract class is designed to facilitate the splitting of text into chunks with a defined size and overlap. It is a foundational component for text processing tasks where segmentation of text is required, such as in natural language processing or data analysis.\
The class is initialized with parameters that determine how text is chunked and how overlaps between chunks are handled. The functionality allows for flexible customization by providing a function to calculate the length of the text, which can be overridden as needed.

## Properties

### ![](/files/KL0Ik37djZRr8a07Wopd) ChunkOverlap

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets the overlap size between chunks.

### ![](/files/KL0Ik37djZRr8a07Wopd) ChunkSize

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets the defined chunk size used for splitting text.

## Methods

### ![](/files/KL0Ik37djZRr8a07Wopd) JoinDocs(docs, separator)

Joins a list of document strings using the specified separator and returns null if the resulting string is empty.

| Parameter     | Type                                                                                                       | Description                                                   |
| ------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| **docs**      | [IReadOnlyList\<String>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1) | A list of document strings to be joined.                      |
| **separator** | [String](https://docs.microsoft.com/dotnet/api/system.string)                                              | The separator to be used between documents when joining them. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The joined string or null if the result is empty.

This method is useful for concatenating text fragments into a single string. It ensures that if the result is an empty string, it returns null instead, which can be useful for avoiding unnecessary processing of empty outputs.

### ![](/files/KL0Ik37djZRr8a07Wopd) MergeSplits(splits, separator)

Merges a list of text splits into larger chunks of the specified chunk size, ensuring overlap is maintained as needed.

| Parameter     | Type                                                                                                   | Description                                        |
| ------------- | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| **splits**    | [IEnumerable\<String>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) | The text segments to be merged into larger chunks. |
| **separator** | [String](https://docs.microsoft.com/dotnet/api/system.string)                                          | The separator to use when joining segments.        |

**Returns:** [String\[\]](https://docs.microsoft.com/dotnet/api/system.string). An array of merged text chunks.

This method processes a list of text splits and combines them into larger chunks while respecting the defined chunk size and overlap. It handles character replacements to standardize the text format and ensures that no chunk exceeds the defined size without appropriate logging mechanisms, which are to be implemented.\
Usage example:

```csharp

TextSplitterServiceBase splitter = new YourTextSplitterService(100, 10, str => str.Length);
string[] mergedChunks = splitter.MergeSplits(new List<string> { "text1", "text2" }, " ");

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when *splits* is null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Split(text)

Splits the given text into an array of strings based on the implemented logic in derived classes.

| Parameter | Type                                                          | Description                       |
| --------- | ------------------------------------------------------------- | --------------------------------- |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to be split into chunks. |

**Returns:** [String\[\]](https://docs.microsoft.com/dotnet/api/system.string). An array of strings representing the split text chunks.

## Inherited By

| Name                                                                                                                                                 | Description                                                                                                                                                                                                        |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [RecursiveCharacterTextSplitterService](/ai/components/api/services/itextsplitterservice/wisej.ai.services.recursivecharactertextsplitterservice.md) | A service for recursively splitting text into chunks based on specified separators and chunk size constraints. This service attempts to split text by different characters to find an optimal separation strategy. |

## Implements

| Name                                                                        | Description                                                          |
| --------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [ITextSplitterService](/ai/components/api/services/itextsplitterservice.md) | Represents a service for splitting text into an array of substrings. |


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/itextsplitterservice/wisej.ai.services.textsplitterservicebase.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
