zoukankan      html  css  js  c++  java
  • 字符串和Stream 分割

    字符串分割:

    public List<StringBuilder> SplitLength(StringBuilder SourceString, int Length)
            {
                List<StringBuilder> list = new List<StringBuilder>();
                try
                {                
                    Length = Length * 1024 * 1024 * 2;
    
    
                    for (int i = 0; i < SourceString.Length; i += Length)
                    {
                        if ((SourceString.Length - i) >= Length)
                            list.Add(new StringBuilder(SourceString.ToString(i, Length)));
                        else
                            list.Add(new StringBuilder(SourceString.ToString(i, SourceString.Length - i)));
                    }                
                }
                catch (Exception e)
                { }
                return list;
            }

    Stream 分割:

    private static List<byte[]> SplitLength(MemoryStream stream)
            {
                int Length = 2 * 1024 * 1024;
                List<byte[]> bytelist = new List<byte[]>();
                int streamlength = (int)stream.Length;
                stream.Seek(0, SeekOrigin.Begin);
    
                for (int i = 0; i < streamlength; i += Length)
                {
                    if ((streamlength - i) >= Length)
                    {
                        byte[] bt = new byte[Length];
                        stream.Read(bt, 0, Length);
                        bytelist.Add(bt);
                    }
                    else
                    {
                        int lastlen = streamlength - i;
                        byte[] bt = new byte[lastlen];
                        stream.Read(bt, 0, lastlen);
                        bytelist.Add(bt);
                    }
                }
                return bytelist;
            }
  • 相关阅读:
    博客园CSS备份4
    博客园css备份3
    CSS透明滚动条效果
    AHK
    修改网页css的插件stlylebot
    欧陆词典CSS修改
    油猴脚本修改网页默认字体
    博客园上传css,js文件并引用
    CSS添加本地字体文件
    博客园css备份
  • 原文地址:https://www.cnblogs.com/lili9696189/p/11314578.html
Copyright © 2011-2022 走看看