public static string ReadLine(this BinaryReader obj) { byte[] pattern = Encoding.ASCII.GetBytes("\r\n"); List <byte> bytes = new List <byte>(); int count = 0; do { var buffer = obj.ReadBytes(4096); count = buffer.Length; if (count > 0) { bytes.AddRange(buffer); } // Find the newline pattern int match = bytes.FindFirstMatch(pattern); if (match != -1) { // reset the stream to just after the newline obj.BaseStream.Seek(match - bytes.Count + 2, SeekOrigin.Current); return(bytes.ConvertToString(match)); } } while (count == 4096); return(Encoding.ASCII.GetString(bytes.ToArray())); }
static void Main(string[] args) { #region RegionName //Console.Write("Input number:"); //var input = Console.ReadLine(); //int result; //if(int.TryParse(input, out result)) //{ // //var isEven = Helper.IsEven(result); // if(result.IsEven()) // Console.WriteLine($"{result} - even"); // else // Console.WriteLine($"{result} - not even"); //} #endregion var roads = new List <Road>(); for (int i = 0; i < 10; i++) { var road = new Road(); road.CreateRandomRoad(1, 1000); roads.Add(road); } var mapRoads = roads.ConvertToString(); Console.WriteLine(mapRoads); Console.ReadKey(); }
public ActionResult Add(Pushmessage_Lv model, List<string> sendPlatForm, int chooseType, bool isRedirect) { ViewData.Model = model; int id = model.Id; //todo 为什么这个不能直接拼接呢? model.SendPlatForm = sendPlatForm.ConvertToString(); model.CreateBy = model.UpdateBy = userId; if (chooseType == 1)//==1 表示報團,需要加上改地址 { if (!model.Link.Contains("http://apps.bigline.com.hk/api/mssage.php?typeId=1&categoryID=&categoryName=&tourId=")) model.Link = "http://apps.bigline.com.hk/api/mssage.php?typeId=1&categoryID=&categoryName=&tourId=" + model.Link; } service.AddOrUpdate(model); if (isRedirect) { return RedirectToAction("Index"); } else { if (id > 0) { AddAlertMsg("修改成功"); } else { AddAlertMsg("新增成功"); } } return View(model); }
public override ICollection <byte> Serialize() { var result = new List <byte>(); Length = Payload.Count(); result.AddRange(SerializeDerStructure()); result.AddRange(Payload); var rr = result.ConvertToString(); return(result); }
static void Main(string[] args) { Console.WriteLine("Введите число"); var input = Console.ReadLine(); if (int.TryParse(input, out int result)) { //var isEven = IsEven(result); if (result.IsEven()) { Console.WriteLine("Чётное число "); } else { Console.WriteLine("Нечётное"); } } else { Console.WriteLine("пургу гонишь"); } int h = 182; if (h.IsDividedBy(2)) { Console.WriteLine("Делиться"); } else { Console.WriteLine("NoDivided"); } var roads = new List <Road>(); for (int i = 0; i < 10; i++) { var road = new Road(); road.CreatRandomRoad(1000, 10000); roads.Add(road); } var roadsName = roads.ConvertToString(); Console.WriteLine(roadsName); Console.ReadLine(); }
private void ParseAndReformatJSON(string jsnpath) { string allLines = File.ReadAllText(jsnpath); List <DataHolder> lstDataJson = JsonConvert.DeserializeObject <List <DataHolder> >(allLines); List <FinalData> lstFinalData = new List <FinalData>(); for (int ii = 0; ii < lstDataJson.Count; ii++) { FinalData fd = new FinalData(); fd.DateAndTime = ParseDate(lstDataJson[ii].Date, lstDataJson[ii].Time); try { ParseFatalities(fd, lstDataJson[ii].Fatalities, lstDataJson[ii].Ground); } catch (Exception e) { Console.WriteLine(e); throw; } ParseAboard(fd, lstDataJson[ii].Aboard); fd.Location = lstDataJson[ii].Location; fd.Operator = lstDataJson[ii].Operator; fd.Flight_no = lstDataJson[ii].Flight_no; fd.Route = lstDataJson[ii].Route; fd.AC_type = lstDataJson[ii].AC_type; fd.Registration = lstDataJson[ii].Registration; fd.cn_Ln = lstDataJson[ii].cn_ln; fd.Summary = lstDataJson[ii].Summary; lstFinalData.Add(fd); } JsonSerializerSettings jsnSettings = new JsonSerializerSettings(); jsnSettings.DateFormatString = "dd/MM/yyyy HH:mm"; jsnSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; string NewJson = JsonConvert.SerializeObject(lstFinalData, Formatting.Indented, jsnSettings); File.WriteAllText(new FileInfo(fpath).DirectoryName + "\\NewJson.json", NewJson); File.WriteAllText(new FileInfo(fpath).DirectoryName + "\\NewCSV.csv", lstFinalData.ConvertToString()); }
public virtual List <T2> MakeSyncedCopy(List <T1> reference) { if (reference == null) { return(null); } if (typeof(T1) == typeof(T2)) { return(reference.Cast <T2>().ToList()); } else if (typeof(T2) == typeof(string)) { return(reference.ConvertToString().Cast <T2>().ToList()); } else if (typeof(T2) == typeof(int)) { return(reference.ConvertToInt32().Cast <T2>().ToList()); } else { throw new NotSupportedException("Data type is not supported, own implementation required"); } }
private void ParseAndReformatCSV(string csvpath) { string[] allLines = File.ReadAllLines(csvpath); string[] Headers = allLines[0].Split(new char[] { ',' }); List <FinalData> lstFinalData = new List <FinalData>(); List <List <string> > lstParsedLines = new List <List <string> >(); for (int ii = 1; ii < allLines.Length; ii++) { bool bRes = true; FinalData fd = new FinalData(); string sInputStr = allLines[ii]; lstParsedLines.Add(new List <string>()); string[] s1splitted = sInputStr.Split(','); if (s1splitted.Length == Headers.Length) { for (int jj = 0; jj < s1splitted.Length; jj++) { lstParsedLines[ii - 1].Add(s1splitted[jj]); } } else if (s1splitted.Length > Headers.Length) { for (int jj = 0; jj < s1splitted.Length; jj++) { if (s1splitted[jj].StartsWith("\"") && !s1splitted[jj].EndsWith("\"")) { for (int kk = jj + 1; kk < s1splitted.Length; kk++) { if (s1splitted[kk].EndsWith("\"")) { lstParsedLines[ii - 1].Add(s1splitted.MergeParts(jj, kk)); jj = kk; break; } } } else { lstParsedLines[ii - 1].Add(s1splitted[jj]); } } } else { } bRes &= ParseAndCleanDate(lstParsedLines[ii - 1][0], fd); bRes &= ParseAndCleanTime(lstParsedLines[ii - 1][1], fd); fd.Location = lstParsedLines[ii - 1][2]; fd.Operator = lstParsedLines[ii - 1][3]; fd.Flight_no = lstParsedLines[ii - 1][4]; fd.Route = lstParsedLines[ii - 1][5]; fd.AC_type = lstParsedLines[ii - 1][6]; fd.Registration = lstParsedLines[ii - 1][7]; fd.cn_Ln = lstParsedLines[ii - 1][8]; fd.Summary = lstParsedLines[ii - 1][12]; ParseFatalities(fd, lstParsedLines[ii - 1][10], lstParsedLines[ii - 1][11]); ParseAboard(fd, lstParsedLines[ii - 1][9]); lstFinalData.Add(fd); } File.WriteAllText(new FileInfo(fpath).DirectoryName + "\\NewCSV.csv", lstFinalData.ConvertToString()); }
static void Main(string[] args) { IEnumerable <object> list = new List <object>() { String.Empty, 1, "xxxx", null, 2, 3, 4, new TimeSpan(1, 0, 0), true, ConsoleColor.Blue }; Console.WriteLine(list.ConvertToString()); //string str = "1:0:0,2:0:0,3:0:0,,,,,4:0:0"; //string str = "1,2,3,,,,,4"; //List<int> a = (List<int>)str.ConvertToList<int>(); //a = a; //Console.WriteLine(a.ConvertToString()); //Tuple<int, string, bool>[] tupl = new Tuple<int, string, bool>[] { new Tuple<int, string, bool>(9, "Я", true), new Tuple<int, string, bool>(-1, "Ты", false), new Tuple<int, string, bool>(7, "Он", true) }; //tupl.SortTupleArray<int, string, bool>(1,true); //foreach (Tuple<int, string, bool> t in tupl) //{ //Console.WriteLine(t.Item1 + " "+ t.Item2 +" "+ t.Item3); //} //Singleton<List<string>>.Instance.Add("a"); //Singleton<List<int>>.Instance.Add(1); //Singleton<List<string>>.Instance.Add("b"); //Singleton<List<int>>.Instance.Add(2); //foreach (string str in Singleton<List<string>>.Instance) //{ //Console.WriteLine(str + " "); //} //foreach (int i in Singleton<List<int>>.Instance) //{ //Console.WriteLine(i + " "); //} //int[] array = new int[] { 1, 2, 3, 4, 5 }; //foreach (int i in array) //{ //Console.WriteLine(i + " "); //} //array.SwapArrayElements<int>(2, 3); //foreach (int i in array) //{ // Console.WriteLine(i + " "); //} //Predicate<int>[] predicates = new Predicate<int>[] {i=>i>0,i=>i<5 }; //Predicate<int> c = FunctionExtentions.CombinePredicates<int>(predicates); //Console.WriteLine(predicates[0](6) + " "); //Console.WriteLine(predicates[1](6) + " "); //Console.WriteLine(c(6) + " "); //Console.WriteLine(c(1) + " "); //Console.WriteLine(predicates[0](-1) + " "); //Console.WriteLine(predicates[1](-1) + " "); //Console.WriteLine(c(-1) + " "); //Func<string> f1 = () => (new System.Net.WebClient()).DownloadString("http://www.google.com/"); //Func<string> f1 = () => (new System.Net.WebClient()).DownloadString("http://www.oogle.c/"); //string data = f1.TimeoutSafeInvoke(); //data = data; Console.ReadLine(); }
protected void add_buletin(object sender, EventArgs e) { if (selectedVals.InnerText == "") { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Немае отримувачів. Потрібно вибрати отримувача та натиснути кнопку Вибрати\")</SCRIPT>"); return; } var list = new List<BulletinLink>(); var split = Result.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries); Result = ""; selectedVals.InnerText = Result; foreach (var s in split) { var link = new BulletinLink(-1, _allowedProfile.First(a => a.Name == s).Id, -1, -1); list.Add(link); } var t = DateTime.Today.ToShortDateString(); CampusClient.DeskAddBulletein( CurrentUser.UserAccountId, CurrentUser.FullName, DateTime.Today.ToShortDateString(), DateTime.Parse(dateStart_d.Text + "/" + dateStart_m.Text + "/" + dateStart_y.Text) .ToShortDateString(), DateTime.Parse(dateEnd_d.Text + "/" + dateEnd_m.Text + "/" + dateEnd_y.Text).ToShortDateString(), sub_text.Text, text_text.Text, list.ConvertToString() ); ResetBoard(); }
/// <summary> /// 根据IDS列表筛选数据 /// </summary> /// <param name="list">Id列表</param> /// <returns></returns> public List <Commodity_Stage_Price> SelectByIds(List <int?> list) { return(Commodity_Stage_PriceOper.Instance.SelectByIds(list.ConvertToString())); }