I have a string which contains color tags.
var myString = "My name is <color=#FF00EE>ABCDE</color> and I love <color=#FFEE00>music</color>";
My string becomes "My name is ABCDE*(pink)* and I love music*(yellow)*"
I want to truncate if the string reaches max length but still keep color tag
var myTruncateString = "My name is <color=#FF00EE>ABCDE</color> and I love <color=#FFEE00>mu</color>";
My string becomes "My name is ABCDE*(pink)* and I love mu*(yellow)*"
Do you have any suggestion?
var stringWithoutFormat = String.Copy(myString);
stringWithoutFormat = Regex.Replace(stringWithoutFormat, "<color.*?>|</color>", "");
var maxLength = 20;
if (stringWithoutFormat.Length > maxLength)
{
// What should I do next?
}