Format special characters in headings so that they can be wrapped.

Source: Internet
Author: User
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>");







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.