zoukankan      html  css  js  c++  java
  • 用于剪切字符串

    /// <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;
        }
  • 相关阅读:
    用Fusion Log诊断同一版本冲突问题解决
    SQLSERVER 切换数据库为单用户和多用户模式
    redis常用命令
    linq函数All,Any,Aggregate说明
    rabbitmq部署安装
    Centos7防火墙常用命令
    SQL SERVER添加表注释、字段注释
    Windows定时任务管理以及服务管理
    SQLServer 2008数据库查看死锁、堵塞的SQL语句
    SQLServer查询死锁
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1528564.html
Copyright © 2011-2022 走看看