markus / KCOM / Converters / StringMultiLineConvert.cs @ c854511f
이력 | 보기 | 이력해설 | 다운로드 (1.23 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Globalization; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Windows.Data; |
8 |
|
9 |
namespace KCOM.Converters |
10 |
{ |
11 |
public class StringMultiLineConvert : IValueConverter |
12 |
{ |
13 |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
14 |
{ |
15 |
StringBuilder builder = new StringBuilder(); |
16 |
|
17 |
if (value != null) |
18 |
{ |
19 |
string str = value.ToString(); |
20 |
|
21 |
//var array = str.Split(new char[] { '\\', 'n' }, StringSplitOptions.RemoveEmptyEntries); |
22 |
var array = System.Text.RegularExpressions.Regex.Split(str, "\n"); |
23 |
|
24 |
int takeLineCount = array.Count(); |
25 |
|
26 |
if (parameter != null) |
27 |
{ |
28 |
int.TryParse(parameter.ToString(), out takeLineCount); |
29 |
} |
30 |
|
31 |
array.Take(takeLineCount).ToList().ForEach(x => builder.AppendLine(x)); |
32 |
} |
33 |
|
34 |
return builder.ToString(); |
35 |
} |
36 |
|
37 |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
38 |
{ |
39 |
throw new NotImplementedException(); |
40 |
} |
41 |
} |
42 |
} |