C#

ListView를 tab문자열로 변환

안녕1999 2020. 10. 24. 23:50
	static public string ListView_GetLine(ListView list, int i,string spilt="\t")
	{
		var builder = new StringBuilder();
		int c;
		for(c=0;c< list.Columns.Count;c++)
		{
			builder.AppendLine(list.Items[i].Text+ spilt);
		}
		return builder.ToString();
	}
	static public string ListViewItem_ToLine(ListViewItem item, string spilt = "\t")
	{
		string s;
		var builder = new StringBuilder();
		int c;
		for (c = 0; c < item.SubItems.Count; c++)
		{
			s = item.SubItems[c].Text.Replace("\r\n", "");
			s = s.Replace("\n", "");

			builder.Append(s+ spilt);
		}
		return builder.ToString();
	}
	static public void ListView_CopySelectedToClipboard(ListView list)
	{
		var builder = new StringBuilder();
		foreach (ListViewItem item in list.SelectedItems)
		{
			builder.AppendLine(ListViewItem_ToLine(item));
		}
		Clipboard.SetText(builder.ToString());
	}
	static public string SpiltLine(ref string str,char spilt_char='\n')
	{
		int len;
		string s;
		len = str.IndexOf(spilt_char);
		if (len > 0)
		{
			s = str.Substring(0, len);
			str = str.Substring(len + 1, str.Length - len-1);
		}
		else
		{
			s = str;
			str = "";
		}
		s=s.Replace("\r", "");
		return s;
	}