zoukankan      html  css  js  c++  java
  • 截取字符窜(区分中英文)

       /// <summary>
            /// 截取字符窜
            /// </summary>
            /// <param name="p_SrcString">待截取字符串</param>
            /// <param name="p_Length">截取字符串长度</param>
            /// <returns></returns>
            public static string GetSubString(string p_SrcString, int p_Length)
            {
                string myResult = p_SrcString;
                if (p_Length >= 0)
                {
                    byte[] bsSrcString = System.Text.Encoding.GetEncoding("GB2312").GetBytes(p_SrcString);
                    if (bsSrcString.Length > p_Length)
                    {
                        int nRealLength = p_Length;
                        int[] anResultFlag = new int[p_Length];
                        byte[] bsResult = null;
                        int nFlag = 0;
                        for (int i = 0; i < p_Length; i++)
                        {
                            if (bsSrcString[i] > 127)
                            {
                                nFlag++;
                                if (nFlag == 3)
                                    nFlag = 1;
                            }
                            else
                                nFlag = 0;
                            anResultFlag[i] = nFlag;
                        }
                        if ((bsSrcString[p_Length - 1] > 127) && (anResultFlag[p_Length - 1] == 1))
                            nRealLength = p_Length + 1;
                        bsResult = new byte[nRealLength];
                        Array.Copy(bsSrcString, bsResult, nRealLength);
                        myResult = Encoding.GetEncoding("GB2312").GetString(bsResult) + "...";
                    }
                }
                return myResult;
            }

  • 相关阅读:
    DataBindings 与 INotifyPropertyChanged 实现自动刷新 WinForm 界面
    EasyInvoice 使用教程
    下载网页通用类
    c#操作excel的一些记录
    sql数据库基础知识整理,常用函数及常用语法
    动态行转列 pivot实现
    EFCodeFirst 数据迁移问题~
    asp.net 翻页时用ViewState保存上一页checkbox勾选的值
    参数化拼接in查询条件,个人备份
    retry
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253294.html
Copyright © 2011-2022 走看看