-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharactersOrderInAText.cs
More file actions
29 lines (28 loc) · 921 Bytes
/
CharactersOrderInAText.cs
File metadata and controls
29 lines (28 loc) · 921 Bytes
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
namespace DA.Algorithms.Strings
{
public static class CharactersOrderInAText
{
/// <summary>
/// Find if the characters of a pattern are in the same order in the source.
/// </summary>
public static bool PatternOrder (string source, string pattern)
{
return PatternOrder (source.ToCharArray (), pattern.ToCharArray ());
}
/// <summary>
/// Find if the characters of a pattern are in the same order in the source.
/// </summary>
public static bool PatternOrder (char[] source, char[] pattern)
{
int counter = 0;
for (int i = 0; i < source.Length; i++)
{
if (source[i] == pattern[counter])
++counter;
if (counter == pattern.Length)
return true;
}
return false;
}
}
}