日期:2014-05-18 浏览次数:20808 次
//this.textBox2.Lines是string[] this.textBox2.Lines = new String[3]{"abc","cde","fgh"};
------解决方案--------------------
public string[] Lines { get { string text = this.Text; ArrayList arrayList = new ArrayList(); int j; for (int i = 0; i < text.Length; i = j) { for (j = i; j < text.Length; j++) { char c = text[j]; if (c == '\r' || c == '\n') { break; } } string value = text.Substring(i, j - i); arrayList.Add(value); if (j < text.Length && text[j] == '\r') { j++; } if (j < text.Length && text[j] == '\n') { j++; } } if (text.Length > 0 && (text[text.Length - 1] == '\r' || text[text.Length - 1] == '\n')) { arrayList.Add(""); } return (string[])arrayList.ToArray(typeof(string)); } set { if (value != null && value.Length > 0) { StringBuilder stringBuilder = new StringBuilder(value[0]); for (int i = 1; i < value.Length; i++) { stringBuilder.Append("\r\n"); stringBuilder.Append(value[i]); } this.Text = stringBuilder.ToString(); return; } this.Text = ""; } }