-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuAcronym.pas
42 lines (32 loc) · 930 Bytes
/
uAcronym.pas
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
unit uAcronym;
interface
function abbreviate(aPhrase: string): string;
implementation
uses SysUtils
,RegularExpressions
,System.Generics.Collections;
function abbreviate(aPhrase: string): string;
function findWords(inputPhrase: string): TMatchCollection;
begin
inputPhrase := inputPhrase.Replace('''s', '');
result := TRegex.Matches(inputPhrase,'[A-Z]+[a-z]*|[a-z]+');
end;
function makeListOfWords(aMatches: TMatchCollection): TList<string>;
begin
result := TList<string>.create;
for var lMatch: TMatch in aMatches do
if lMatch.Success then
result.Add(lMatch.Value);
end;
function ExtractAndUpcaseFirstLetters(aWords: TList<string>): string;
begin
result := '';
for var _Word in aWords do
result := result + _Word.ToUpperInvariant[1];
end;
begin
result := ExtractAndUpcaseFirstLetters(
makeListOfWords(
findWords(aPhrase)));
end;
end.