-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringHelper.cs
More file actions
118 lines (106 loc) · 3.56 KB
/
Copy pathStringHelper.cs
File metadata and controls
118 lines (106 loc) · 3.56 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Panda3
{
/// <summary>
/// helper class for operatios on text
/// </summary>
public class StringHelper
{
/// <summary>
/// function to count punctional marks ('.' and '?' only) in text
/// </summary>
public static int CountPunctuationMark(string text)
{
char[] chars = text.ToCharArray();
int numberOfPunctuationMarks = 0;
for (int i = 0; i < chars.Length; i++)
{
if(chars[i] == '.' || chars[i] == '?')
{
numberOfPunctuationMarks++;
}
}
return numberOfPunctuationMarks;
}
/// <summary>
/// function for counting sentences with '.' and '?'
/// </summary>
public static int CountSentenses(string text)
{
string[] sentenses = text.Split(new char[] { '.', '?' }, StringSplitOptions.RemoveEmptyEntries);
return sentenses.Length;
}
/// <summary>
/// function for counting letters
/// </summary>
public static int CountVowels(string text)
{
char[] chars = text.ToCharArray();
int numberOfVowes = 0;
for (int i = 0; i < text.Length; i++)
{
if (
char.IsLetter(chars[i]) == true
&& (chars[i].ToString().ToLower() == "a" || chars[i].ToString().ToLower() == "e" || chars[i].ToString().ToLower() == "i"
|| chars[i].ToString().ToLower() == "o" || chars[i].ToString().ToLower() == "u" || chars[i].ToString().ToLower() == "y")
)
{
numberOfVowes = numberOfVowes + 1;
}
}
return numberOfVowes;
}
public static int CountConstatnts(string text)
{
char[] chars = text.ToCharArray();
int numberOfLetters = 0;
for (int i = 0; i < text.Length; i++)
{
if (char.IsLetter(chars[i]) == true)
{
numberOfLetters = numberOfLetters + 1;
}
}
return numberOfLetters - StringHelper.CountVowels(text);
}
public static int CountWordsWithout1letterWords(string text)
{
char[] chars = text.ToCharArray();
string newText = "";
for (int i = 0; i < chars.Length; i++)
{
if (char.IsPunctuation(chars[i]) != true && char.IsDigit(chars[i]) != true && char.IsWhiteSpace(chars[i]) != true)
{
newText = newText + chars[i].ToString();
}
else
{
newText = newText + " ";
}
}
string[] words = newText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
int numberOfWords = 0;
for (int i = 0; i < words.Length; i++)
{
if (words[i].Length > 1)
{
numberOfWords++;
}
}
return numberOfWords;
}
public static int[] CountDiffLetters(string text)
{
int[] c = new int[(int)char.MaxValue];
foreach (char t in text)
{
c[(int)t]++;
}
return c;
}
}
}