Show
Recently made a forum, found in the title if there are consecutive letters or other special characters, such as ¥, $,. ,,, ~,! 、、、? , * 、..., this will result in the inability to wrap, the solution is to use the following methods, when the title of consecutive letters or special characters to reach a certain length, you can use the specified tag to force a newline.
public static string Formatstr (string str, int len, string tag)
{
char[] Arrchar = new char[10]{'. ', ', ', ', ', '! ','、','? ', ' * ', ' ... ', ' ¥ ', ' $ '};
StringBuilder sb = new StringBuilder ();
int i = 0;
foreach (char char in str)
{
BOOL Biscontain = false;
for (int j = 0; J < Arrchar.length; J + +)
{
if (Char.compareto (arrchar[j]) = = 0)
{
Biscontain = true;
Break
}
}
if ((int) Char <= 127 | | biscontain)
i + 1;
Else
i = 0;
Sb. Append (Convert.ToString (Char));
if (i > Len)
{
Sb. Append (tag);
i = 0;
}
}
Return SB. ToString ();
}
Call Method:
String str = "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$";
Formatstr (str, ten, "<br>");