-
Notifications
You must be signed in to change notification settings - Fork 1
/
text-utils.cs
62 lines (47 loc) · 2.4 KB
/
text-utils.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuickFix.Classes
{
public class TextUtils
{
private static Random random = new Random();
public static bool TextContainsOnlyLatters(string text) => text.All(Char.IsLetter) ? true : false;
public static bool TextContainsNumbersLatters(string text) => text.All(Char.IsLetterOrDigit) ? true : false;
public static bool TextContainsOnlyNumbers(string text) => text.All(Char.IsDigit) ? true : false;
public static bool TextContainsSymbols(string text) => text.All(Char.IsSymbol) ? true : false;
public static bool TextContainsSpaces(string text) => text.All(Char.IsWhiteSpace) ? true : false;
public static bool ListContainsString(List<string> list, string text) => list.Where(CheckString => CheckString.Contains(text)) != null ? true : false;
public bool ListContainsString(List<string> list, string text) => list.Where(CheckString => CheckString.Contains(text)) != null;
public List<string> ListAddStringsToList(List<string> list, string[] strings) {
for (int i = 0; i < strings.Length; i++)
list.Add(strings[i]);
return list;
}
public List<string> ListRemoveStringsFromList(List<string> list, string[] strings) {
for (int i = 0; i < strings.Length; i++)
list.Remove(strings[i]);
return list;
}
public static List<string> ListAddStringsToList(List<string> list, string[] strings) {
for (int i = 0; i < strings.Length; i++)
list.Add(strings[i]);
return list;
}
public static List<string> ListRemoveStringsFromList(List<string> list, string[] strings) {
for (int i = 0; i < strings.Length; i++)
list.Remove(strings[i]);
return list;
}
public static string RandomChars(int length) {
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public static string RandomNums(int length) {
const string chars = "1234567890";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
}