public void StringSplitByStrings() { const string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Cras convallis, nulla eget faucibus sagittis, dolor."; string[] expected1 = { "Lorem ipsum dolor sit amet", "consectetur adipiscing elit", "Cras convallis", "nulla eget faucibus sagittis", "dolor", "" }; string[] result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, StringSplitOptions2.None); Assert.AreEqual(expected1.Length, result.Length); if (!result.SequenceEqual(expected1)) { Assert.Fail("String split by string test #1"); } string[] expected2 = new string[expected1.Length - 1]; Array.Copy(expected1, expected2, expected2.Length); result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, StringSplitOptions2.RemoveEmptyEntries); Assert.AreEqual(expected2.Length, result.Length); if (!result.SequenceEqual(expected2)) { Assert.Fail("String split by string test #2"); } }
public void StringSplitByStringsCount() { const string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Cras convallis, nulla eget faucibus sagittis, dolor."; string[] expected1 = { "Lorem ipsum dolor sit amet", "consectetur adipiscing elit", "Cras convallis, nulla eget faucibus sagittis, dolor.", }; string[] result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, 3, StringSplitOptions2.None); Assert.AreEqual(expected1.Length, result.Length); if (!result.SequenceEqual(expected1)) { Assert.Fail("String split count by string test #1"); } result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, 3, StringSplitOptions2.RemoveEmptyEntries); Assert.AreEqual(expected1.Length, result.Length); if (!result.SequenceEqual(expected1)) { Assert.Fail("String split count by string test #2"); } result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, 1, StringSplitOptions2.None); Assert.AreEqual(1, result.Length); Assert.AreEqual(text, result[0], "String split count by string test #3"); result = String2.Split(text, new string[] { ", ", ". ", ",", "." }, 1, StringSplitOptions2.RemoveEmptyEntries); Assert.AreEqual(1, result.Length); Assert.AreEqual(text, result[0], "String split count by string test #4"); }
public HandShake(String2 data) { String2[] buffer = data.Split(String2.CRLF + String2.CRLF)[0].Split(String2.CRLF); if (buffer.Length < 1) { throw new FormatException(); } header = buffer[0]; option = (from step1 in buffer where !header.Equals(step1) let step2 = step1.Split(":") where step2.Length >= 2 let key = step2[0].Trim().ToUpper() let value = step1.Replace(step2[0], "").Replace(":", "").Trim() select new { k = key, v = value }) .ToDictionary(i => i.k, i => i.v); }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) { //validate if (item == null) { return(DefaultTemplate); } //get string var str = item as string; if (item.GetType().IsPrimitive || item.GetType().IsEnum) { str = item.ToString(); } //select template if (str == null) { return(DefaultTemplate); } if (String1 != null && String1.Split(',').Contains(str)) { return(Template1); } if (String2 != null && String2.Split(',').Contains(str)) { return(Template2); } if (String3 != null && String3.Split(',').Contains(str)) { return(Template3); } if (String4 != null && String4.Split(',').Contains(str)) { return(Template4); } if (String5 != null && String5.Split(',').Contains(str)) { return(Template5); } if (String6 != null && String6.Split(',').Contains(str)) { return(Template6); } if (String7 != null && String7.Split(',').Contains(str)) { return(Template7); } if (String8 != null && String8.Split(',').Contains(str)) { return(Template8); } if (String9 != null && String9.Split(',').Contains(str)) { return(Template9); } if (String10 != null && String10.Split(',').Contains(str)) { return(Template10); } return(DefaultTemplate); }
public Request(IServer server, String2 request) { _server = server; request = request.Trim(); _request = request; String2[] temp_header = request.Split(new String2("\r\n")); String2 state = temp_header[0]; String2[] temp_state = state.Split(" "); Method = temp_state[0].Trim(); Uri = temp_state[1].Trim(); int pos = Uri.IndexOf("?"); if (pos > -1) { String2 temp_uri = Uri.SubString(pos + 1, Uri.Length - (pos + 1)).Trim(); Uri = Uri.SubString(0, pos).Trim(); String2[] temp_query_string = temp_uri.Split("&"); foreach (var t in temp_query_string) { pos = t.IndexOf("="); if (pos < 0) { continue; } String2 key = t.SubString(0, pos).Trim(); String2 value = t.SubString(pos + 1, t.Length - (pos + 1)).Trim(); if (_query_string.ContainsKey(key)) { _query_string.Remove(key); } _query_string.Add(key, value); } } Version = temp_state[2].Trim(); for (int i = 1; i < temp_header.Length; i++) { String2[] temp = temp_header[i].Separate(":"); if (temp == null) { var post_value = temp_header[i].Split("&"); foreach (var val in post_value) { temp = val.Separate("="); if (temp == null) { continue; } if (_post_string.ContainsKey(temp[0])) { _post_string.Remove(temp[0]); } _post_string.Add(temp[0], temp[1]); } continue; } if (_header.ContainsKey(temp[0])) { _header.Remove(temp[0]); } _header.Add(temp[0], temp[1]); } if (_header.ContainsKey("Host")) { this.Host = _header["Host"]; } else { this.Host = new String2(0); } if (_header.ContainsKey("Cookie")) { String2 temp = _header["Cookie"]; String2[] cks = temp.Split(";"); foreach (var c in cks) { var t = c.Separate("="); if (_cookie.ContainsKey(t[0])) { _cookie.Remove(t[0]); } _cookie.Add(t[0], t[1]); } } }