UTF-16 safe substring in C# .NET
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to get a substring of a given length say 150. However, I want to make sure I don't cut off the string in between a unicode character. e.g. see the following code: Here substr is an invalid string since the smiley character is cut in half. Instead I want a function that does as follows: where substr For reference, here is how I would do it in Objective-C using rangeOfComposedCharacterSequencesForRange What is the equivalent code in C#? 回答1: This should return the maximal substring starting at index startIndex and with length up to