-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringExtensions.cs
64 lines (59 loc) · 1.91 KB
/
StringExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace StEn.X3270.Rest.Extensions
{
using System;
/// <summary>
/// String extensions.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Takes a mask in ASCII representation (new line separated lines of ASCII symbols) and transforms it to a 2d array of ASCII symbols.
/// </summary>
/// <param name="mask">
/// The mask.
/// </param>
/// <returns>
/// The <see>
/// <cref>string[][]</cref>
/// </see>
/// .
/// </returns>
public static string[][] ToAsciiMatrix(this string mask)
{
var lines = mask.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
var returnStr = new string[lines.Length][];
for (var i = 0; i < lines.Length; i++)
{
returnStr[i] = new string[lines[i].Length];
for (var j = 0; j < lines[i].Length; j++)
{
returnStr[i][j] = lines[i][j].ToString();
}
}
return returnStr;
}
/// <summary>
/// Takes a mask in byte representation (new line separated lines of bytes) to a 2d array of byte symbols.
/// </summary>
/// <param name="mask">
/// The mask.
/// </param>
/// <returns>
/// The <see>
/// <cref>string[][]</cref>
/// </see>
/// .
/// </returns>
public static string[][] ToByteMatrix(this string mask)
{
var lines = mask.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
var returnStr = new string[lines.Length][];
for (var i = 0; i < lines.Length; i++)
{
var line = lines[i].Split(' ');
returnStr[i] = line;
}
return returnStr;
}
}
}