Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created February 23, 2024 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/c3fb6bb7f3675b229577879508f00108 to your computer and use it in GitHub Desktop.
Save bjoerntx/c3fb6bb7f3675b229577879508f00108 to your computer and use it in GitHub Desktop.
// split a text into chunks
private static List<string> CreateChunks(string text, int chunkSize, int overlap)
{
List<string> chunks = new List<string>();
// split the text into chunks
while (text.Length > chunkSize)
{
chunks.Add(text.Substring(0, chunkSize));
text = text.Substring(chunkSize - overlap);
}
// add the last chunk
chunks.Add(text);
return chunks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment