forked from devspexx/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextUtils.cs
48 lines (38 loc) · 1.91 KB
/
TextUtils.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuickFix.Classes
{
public class TextUtils
{
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 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;
}
private static Random random = new Random();
public static string RandomChars(int dolzina) {
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // %@#()$?*_[]+-
return new string(Enumerable.Repeat(chars, dolzina)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public static string RandomNums(int dolzina) {
const string chars = "1234567890";
return new string(Enumerable.Repeat(chars, dolzina)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
}