Appreciate the clarification. It looks like you want to input numbers separated by spaces and have them sorted while maintaining leading zeros. If so, try the following:
private void textBox1_TextChanged(object sender, EventArgs e)
{
// Read the input from textBox1 and split by spaces
string input = textBox1.Text.Trim();
string[] numbers = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
// Check if all elements are valid numbers
if (numbers.All(n => int.TryParse(n, out _)))
{
// Sort numbers while preserving leading zeros
var sortedNumbers = numbers.OrderBy(n => n).ToArray();
// Join them back into a space-separated string
textBox2.Text = string.Join(" ", sortedNumbers);
}
else
{
textBox2.Text = "Invalid input"; // Display error if input is not numeric
}
}
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin