Hej!
Przejdę od razu do rzeczy bez zbędnych wstępów. To co chcę zrobić to wyciągnąć zmienną, liczbę od 1 do 12 z tekstu:
Remove Fishing rod o-matic
Item Level: 3
Item XP: 1,345
Mam opracowane fajne funkcje Before & After
function After(s, str: string): string;
var
p, strL, sL: Integer;
begin
sL := Length(s);
strL := Length(str);
if (sL < strL) then
begin
p := Pos(s, str);
if (p > 0) then
Result := Copy(str, (p + sL), ((1 + strL) - (p + sL)));
end else
Result := '';
end;
var
str: string;
begin
ClearDebug;
str := 'What comes after this? After() WORKS!';
WriteLn(After('this? ', str));
end.
function Before(s, str: string): string;
var
p: Integer;
begin
if (Length(s) < Length(str)) then
begin
p := Pos(s, str);
if (p > 1) then
Result := Copy(str, 1, (p - 1))
else
Result := '';
end else
Result := '';
end;
var
str: string;
begin
ClearDebug;
str := 'Before() WORKS! Test to see if Before() works correctly.';
WriteLn(Before(' Test', str));
end.
umieszczam to żeby mi przycięło After ':' i Before #13#10 Item XP i zwykle otrzymuję numer jako string, robię for i := 1 to 10 do intToStr
i mam to co chciałem.
CAŁY PROBLEM polega na tym, że czasami źle zczyta mi tekst i dwukropek pojawi się w taki sposób:
zamiast:
Item Level: 3
to
Item Level :3 i od razu cała funkcja crashuje. Czy ma ktoś pomysł jak wyciągnąć Item Level, biorąc pod uwagę ten wędrujący dwukropek? Męczę się z tym od dłuższego czasu i nie mogę nic sensownego wymyśleć. Mam nadzieję, że w miarę jasno przedstawiłem mój problem. Dzięki!