循环数组

Title

Codeid ="1;2;3;4;5;6";

string Codeidall = Codeid.ToString( ).TrimEnd( ';');

   string[] Codes = Func.Split( Codeidall , ';' );


    for ( int i = 0 ; i <= Codes.Length ; i++ )
    {
     if ( _PayMentid.ToLower( ).ToString( ) == Codes[i].ToString( ) )
     {
      return false;
      break;
     }
    }

 

 

Title

//分割数组

 public static string[] Split(string Value, char separator)
        {
            string[] aResult = null;
            if (!string.IsNullOrEmpty(Value))
            {
                if (Value.Contains(separator.ToString()))
                {
                    aResult = Value.Split(separator);
                }
                else
                {
                    aResult = new string[1] { Value };
                }
            }
            return aResult;
        }

 

        
Title /// <summary>
        /// 去除文件名中的特殊字符
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static string GetSafeFileName(string Value)
        {
            string[] arr = new string[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" };
            foreach (string c in arr)
            {
                Value = Value.Replace(c, "_");
            }
            return Value;
        }

 

Title/// <summary>
        /// 向指定文件路径写入信息
        /// </summary>
        /// <param name="Path">文件全路径</param>
        ///<param name="Message">需要写入的信息</param>
        /// <returns></returns>
        public static void WriteLog(string Path, string Message)
        {
            System.IO.StreamWriter w;
            try
            {
                if (!System.IO.File.Exists(Path))
                {
                    System.IO.FileStream fs = System.IO.File.Create(Path);
                    fs.Close();
                }
                w = System.IO.File.AppendText(Path);
                w.WriteLine(System.DateTime.Now.ToString() + ":" + Message);
                w.Close();
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("日志写入异常,错误原因为:" + ex.Message);
            }
        }
posted @ 2012-02-03 13:10  尘满布衣  阅读(174)  评论(0)    收藏  举报