Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以C为单位的mb结构?_C#_Php_String - Fatal编程技术网

C# 以C为单位的mb结构?

C# 以C为单位的mb结构?,c#,php,string,C#,Php,String,有人知道php函数mb#u struct在C#中的实现吗 mb_strcut()从字符串中提取子字符串,类似于mb_substr(),但以字节而不是字符进行操作。如果剪切位置恰好位于多字节字符的两个字节之间,则从该字符的第一个字节开始执行剪切。这也是substr()函数的不同之处,substr()函数只会在字节之间剪切字符串,从而导致字节序列格式错误 谢谢,没有你的帮助,Dash不可能写下面的内容 public static string LimitByteLength(string

有人知道php函数mb#u struct在C#中的实现吗


mb_strcut()从字符串中提取子字符串,类似于mb_substr(),但以字节而不是字符进行操作。如果剪切位置恰好位于多字节字符的两个字节之间,则从该字符的第一个字节开始执行剪切。这也是substr()函数的不同之处,substr()函数只会在字节之间剪切字符串,从而导致字节序列格式错误

谢谢,没有你的帮助,Dash不可能写下面的内容

    public static string LimitByteLength(string input, int startByte, int byteLength)
    {
        var maxLength = startByte + byteLength;
        return 
            new string(
                input.SkipWhile((c, i) => GetByteCount(input.Substring(0, i + 1)) <= startByte)
                    .TakeWhile((c, i) => GetByteCount(input.Substring(0, i + 1)) <= maxLength).ToArray());
    }

    private static int GetByteCount(string input)
    {
        return Encoding.Unicode.GetByteCount(input);
    }
publicstaticstringlimitbytelength(字符串输入,int起始字节,int byteLength)
{
var maxLength=起始字节+字节长度;
返回
新字符串(

input.SkipWhile((c,i)=>GetByteCount(input.Substring(0,i+1))GetByteCount(input.Substring(0,i+1))给出你最终想要得到的具体例子。举例说明你期望
mb_struct
substring
有什么不同。请描述你正在尝试做什么;不要用另一种编程语言的功能来陈述你的需求。这里可能的解决方案是什么?NET中的字符串不是UTF-8o您的字节计数已关闭。