• 用于剪切字符串


    /// <summary>
        /// 用于剪切字符串
        /// </summary>
        /// <param name="sInString"> 字符串</param>
        /// <param name="iCutLength">留字符串的长度</param>
        /// <returns></returns>
        public static string CutStr(string sInString, int iCutLength)
        {
            if (sInString == null || sInString.Length == 0 || iCutLength <= 0)
                return "";
            int iCount = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(sInString);
            if (iCount > iCutLength)
            {
                int iLength = 0;
                for (int i = 0; i < sInString.Length; i++)
                {
                    int iCharLength = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(new char[] { sInString[i] });
                    iLength += iCharLength;
                    if (iLength == iCutLength)
                    {
                        sInString = sInString.Substring(0, i + 1);
                        break;
                    }
                    else if (iLength > iCutLength)
                    {
                        sInString = sInString.Substring(0, i);
                        break;
                    }
                }
            }
            return sInString;
        }
  • 相关阅读:
    $resource详解
    大白话讲解Promise(一)
    《AngularJS》5个实例详解Directive(指令)机制
    Openstack实现共有云VPC的SDN网络
    Openstack实现共有云多flat网络
    Openstack使用NFS作为后端存储
    Openstack块存储cinder安装配置
    Openstack创建镜像
    Openstack深入了解虚拟机
    Python全栈day26-27(面向对象进阶)
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1528564.html
Copyright © 2020-2023  润新知