-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2twits.dpr
68 lines (62 loc) · 1.63 KB
/
text2twits.dpr
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
program text2twits;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes;
var
path, inputFile, inputText, tempText: string;
sl: TStringList;
i, lastSpace, twitCount: Integer;
Const
NEXTTWITCHAR = '🔽';
procedure saveNewTwit(text: String);
begin
sl := TStringList.Create;
sl.text := text;
sl.SaveToFile(path + 'Twit' + intToStr(twitCount) + '.txt', Tencoding.UTF8);
sl.Free;
writeln('Twit ' + intToStr(twitCount) + ' save.');
inc(twitCount);
end;
begin
writeln('Helo text 2 Twits :)');
path := ExtractFilePath(paramstr(0));
if paramCount < 1 then
writeln('Not input Arguments!')
else
begin
inputFile := paramstr(1);
if not FileExists(inputFile) then
writeln('File not Exists!')
else
begin
writeln('Input File:' + inputFile);
sl := TStringList.Create;
sl.LoadFromFile(inputFile, Tencoding.UTF8);
inputText := trim(sl.text);
sl.Free;
writeln('Length input text:' + intToStr(length(inputText)) + ' chars');
twitCount := 1;
tempText := '';
i := 1;
lastSpace := 0;
while length(inputText) > 279 do
begin
if inputText[i] in [#32, #10, #13] then
lastSpace := i;
inc(i);
if i > 278 then
begin
tempText := copy(inputText, 1, lastSpace);
delete(inputText, 1, lastSpace);
saveNewTwit(trim(tempText) + NEXTTWITCHAR);
i := 1;
lastSpace := 0;
tempText := '';
end;
end;
saveNewTwit(inputText);
end;
end;
writeln('Press ENTER to Exit.');
readln;
end.