• 字符串的分割


    由于项目需要自己写了一个字符串分割实现代码以下:


            #region 分割字符串
            /// <param name="strContent">分割前字符串</param>
            /// <param name="strSplit">分割字符</param>
            /// <returns>返回分割后的数组</returns>
            public static string[] SplitString(string strContent, string strSplit)
            {
                if (!string.IsNullOrEmpty(strContent))
                {
                    if (strContent.IndexOf(strSplit) < 0)
                        return new string[] { strContent };

                    return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase);
                }
                else
                    return new string[0] { };
            }

            /// <summary>
            /// 分割字符串
            /// </summary>
            /// <returns></returns>
            public static string[] SplitString(string strContent, string strSplit, int count)
            {
                string[] result = new string[count];
                string[] splited = SplitString(strContent, strSplit);

                for (int i = 0; i < count; i++)
                {
                    if (i < splited.Length)
                        result[i] = splited[i];
                    else
                        result[i] = string.Empty;
                }

                return result;
            }
            #endregion

  • 相关阅读:
    Service(服务)简单使用
    Android设计模式——抽象工厂方法模式
    Android设计模式——工厂方法模式
    算法问题——递归算法
    Android设计模式——Builder(建造者)模式
    Android设计模式——单例模式
    蓝牙4.0权限问题
    Android 网络状态变化的监听
    RecyclerView的使用
    函数参数的引用传递与值传递
  • 原文地址:https://www.cnblogs.com/northeastTycoon/p/2744390.html
Copyright © 2020-2023  润新知