Để chèn khoảng trắng trước chữ cái in hoa, dùng LINQ:
var str = "WelcomeToMyWebsite";
str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
Ví dụ
using System;
using System.Linq;
class Demo {
static void Main() {
var str = "WelcomeToMyWebsite";
Console.WriteLine("Chuỗi gốc: " + str);
str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
Console.WriteLine("Chuỗi mới: " + str);
Console.ReadLine();
}
}