Beispiel #1
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="input"></param>
            /// <param name="sep1"></param>
            /// <param name="sep2"></param>
            /// <param name="pos1"></param>
            /// <param name="flag"></param>
            /// <param name="pos2"></param>
            /// <returns></returns>
            public static string getItem(string input, string sep1, string sep2, int pos1, string flag, int pos2)
            {
                //例如: 串 1,aa;2,bb 由一级分隔符";" 分成两段, 每段又由二级分隔符"," 分开, 第一个参数sIn 是整个字串,
                //sep1 指一级分隔符,sep2是二级分隔符.    如果对于这个串, 想查找子串中, 第1 个位置是2 时, 第二个位置的值,
                //即, pos1 为0, flag为"2", pos2 为1, 函数返回"bb"

                string[] arr;
                string[] arrb;
                arr = StringTool.MSplit(input, sep1);

                foreach (string st in arr)
                {
                    arrb = StringTool.MSplit(st, sep2);
                    if (pos1 >= arrb.Length || pos2 >= arrb.Length)
                    {
                        return("");
                    }
                    for (int i = 0; i < arrb.Length; i++)
                    {
                        if (arrb[pos1] == flag)
                        {
                            return(arrb[pos2]);
                        }
                    }
                }

                return("");
            }
Beispiel #2
0
        /// <summary>
        /// 从'YYYY/MM/DD' 的形式提取出日期型变量
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static DateTime GetDateFromString(string val)
        {
            string pat = "^\\d{4,4}/\\d{2,2}/\\d{2,2}$";

            if (!StringTool.IsMatch(val, pat))
            {
                return(new DateTime());
            }
            string sYear, sMonth, sDay;

            sYear  = StringTool.MTable.getItem(val, " ", "/", 0, 0);
            sMonth = StringTool.MTable.getItem(val, " ", "/", 0, 1);
            sDay   = StringTool.MTable.getItem(val, " ", "/", 0, 2);

            if (sYear == "" || sMonth == "" || sDay == "")
            {
                return(new DateTime());
            }
            else
            {
                DateTime dt = new DateTime(Convert.ToInt32(sYear), Convert.ToInt32(sMonth), Convert.ToInt32(sDay),
                                           0, 0, 0);
                return(dt);
            }
        }
Beispiel #3
0
            }    //end class mTableRow



            //************************************************************



            /// <summary>
            /// 静态方法, 获取一个带分隔符的字串的指定段的值.第三个参数从0开始计数.
            /// 如:getItem("1,2,3",",",1)=="2"
            /// </summary>
            /// <param name="input"></param>
            /// <param name="sep">"分隔符"</param>
            /// <param name="pos">从0开始计数的位置</param>
            /// <returns></returns>
            public static string getItem(string input, string seperator, int pos)
            {
                string[] arr = StringTool.MSplit(input, seperator);

                if (pos >= arr.Length || pos < 0)
                {
                    return("");
                }
                else
                {
                    return(arr[pos]);
                }
            }
Beispiel #4
0
                /// <summary>
                /// 将行导出为字串
                /// </summary>
                /// <returns></returns>
                public override string ToString()
                {
                    if (arrItem == null)
                    {
                        throw new Exception("object is not initialized properly.");
                    }

                    string str = "";

                    for (int i = 0; i < arrItem.Length; i++)
                    {
                        str += arrItem[i] + ",";
                    }
                    str = StringTool.RemoveTail(str, 1);
                    return(str);
                }
Beispiel #5
0
            /// <summary>
            /// 将当前表导出为字符串
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                if (iRow == -1 || iClm == -1 || oRows == null)
                {
                    throw new Exception("null reference. object is not initialized properly.");
                }

                string str = "";

                for (int i = 0; i < iRow; i++)
                {
                    str += oRows[i].ToString() + ";";
                }
                str = StringTool.RemoveTail(str, 1);
                return(str);
            }
Beispiel #6
0
            public static string getItem(string input, string sep1, string sep2, int row, int pos)
            {
                if (input == "")
                {
                    return("");
                }

                string[] arr = StringTool.MSplit(input, sep1);

                if (row >= arr.Length)
                {
                    return("");
                }

                string[] arrb = StringTool.MSplit(arr[row], sep2);

                if (pos >= arrb.Length)
                {
                    return("");
                }

                return(arrb[pos]);
            }
Beispiel #7
0
            /// <summary>
            /// 从指定字符串构造表
            /// </summary>
            /// <param name="val"></param>
            public void FromString(string val)
            {
                if (val.Trim() == "")
                {
                    iRow  = 0;
                    iClm  = 0;
                    oRows = new MTableRow[0];
                    return;
                }


                string[] arrRow = StringTool.MSplit(val, ";");

                int iTemp = 0;

                for (int i = 0; i < arrRow.Length; i++)
                {
                    if (i == 0)
                    {
                        iTemp = StringTool.MSplit(arrRow[i], ",").Length;
                    }
                    else if (StringTool.MSplit(arrRow[i], ",").Length != iTemp)
                    {
                        throw new Exception("Argument is not valid");
                    }
                }

                iClm = iTemp;
                iRow = arrRow.Length;

                oRows = new MTableRow[iRow];
                for (int i = 0; i < iRow; i++)
                {
                    oRows[i] = new MTableRow(arrRow[i]);
                }
            }
Beispiel #8
0
 /// <summary>
 /// 从字串构造行
 /// </summary>
 /// <param name="str"></param>
 public void FromString(string str)
 {
     arrItem = StringTool.MSplit(str, ",");
 }
Beispiel #9
0
 /// <summary>
 /// 从字符串构造一行
 /// </summary>
 /// <param name="str"></param>
 public MTableRow(string str)
 {
     arrItem = StringTool.MSplit(str, ",");
 }