Penthus
Penthus
CC#
Created by Penthus on 7/11/2024 in #help
✅ Splitting string into chunks with delimiter
I am trying to split a string to fit within a character limit for my message. This works but cuts words, I was wondering if there is a way to have the chunk split in a way splits the chunk before a word on the new line. Example data is
John
Ben
Amy
Susan
Bob
Sarah
John
Ben
Amy
Susan
Bob
Sarah
Current result
John
Ben
Amy
Susan

B
ob
Sarah
John
Ben
Amy
Susan

B
ob
Sarah
Desired Result
John
Ben
Amy
Susan

Bob
Sarah
John
Ben
Amy
Susan

Bob
Sarah
Current Code
foreach (var member in members)
{
description += $"{member}\n";
}

if (description.Length < 4096)
{
var message = description;

PostMessage(message);
}
else if (description.Length > 4096)
{
var result = description.Chunk(4096).Select(x => new string(x)).ToList();
foreach (var content in result)
{
PostMessage(message);
}
}
foreach (var member in members)
{
description += $"{member}\n";
}

if (description.Length < 4096)
{
var message = description;

PostMessage(message);
}
else if (description.Length > 4096)
{
var result = description.Chunk(4096).Select(x => new string(x)).ToList();
foreach (var content in result)
{
PostMessage(message);
}
}
10 replies
CC#
Created by Penthus on 5/10/2024 in #help
JSON Deserialize
No description
33 replies
CC#
Created by Penthus on 9/10/2023 in #help
❔ Visual Studio XML Comment Formatting
8 replies