String method to intercept fixed length

xiaoxiao2021-03-06  117

This function is nothing special, that is, it can take a range of strings that can be intercepted. Maybe small feature is that Len is byte, solving the Chinese characters and English bytes. Different lengths are different.

#Region string intercept function public static string cutstring (string infutstring, int LEN) {

Asciiencoding ascii = new asciiencoding (); int Templen = 0; string tempstring = ""; byte [] s = ascii.getbytes (InputString); for (int i = 0; i

If (Templen> Len) Break;} // If you cut, add half a omitted number byte [] mybyte = system.text.encoding.default.getBytes (InputString); if (mybyte.length> len) Tempstring = "... "

Return Tempstring;} #ENDREGION

转载请注明原文地址:https://www.9cbs.com/read-101661.html

New Post(0)