Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.11.26;
Скачать: CL | DM;

Вниз

Нужна помощь   Найти похожие ветки 

 
Marat ©   (2006-11-08 08:29) [0]

Здравствуйте, мастера.
Вопрос такой.
Считываю текстовый файл.
var
 F: TextFile;
 S: string;
 i: integer;
begin
try
   AssignFile(F, "C:\Projects\Bazis\T2_20061101.txt");
   Reset(F);
SG.ColCount := 1;
SG.RowCount := 1;
while not EOF(F) do
begin
ReadLn(F, S);
OemToChar(@S[1],@S[1]);
SG.Col := 0;
while Pos(" ", S) > 0 do
begin
SG.Cells[SG.Col, SG.Row+1] := Copy(S, 1, Pos(" ", S)-1);
Delete(S, 1, Pos(" ", S));
if SG.ColCount - SG.Col = 1
then
begin
SG.ColCount := SG.ColCount + 1
end;
SG.Col := SG.Col + 1;
end;
SG.Cells[SG.Col, SG.Row+1] := S;
SG.RowCount := SG.RowCount + 1;
SG.Row := SG.Row + 1;
end;
SG.RowCount := SG.RowCount - 1;
finally
CloseFile(F);
end;
этот алгоритм верен для файла, в котором слова разделены пробелом.
А у меня файл, в котором между словами может быть 1-8 пробелов. Как быть?


 
Орион ©   (2006-11-08 08:51) [1]

есть такая функция TrimLeft


 
MBo ©   (2006-11-08 08:58) [2]


procedure TForm13.Button2Click(Sender: TObject);
var
 List, TempList: TStringList;
 s: string;
 i: Integer;
begin
 List := TStringList.Create;
 TempList := TStringList.Create;
 List.LoadFromfile("E:\a.txt");
 SG.RowCount := List.Count;
 for i := 0 to List.Count - 1 do begin
   s := List[i];
   OemToCharBuff(PChar(s), PChar(s), Length(s));
   TempList.CommaText := s;
   if SG.ColCount < TempList.Count then
     SG.ColCount := TempList.Count;
   SG.Rows[i].Assign(TempList);
 end;
 List.Free;
 TempList.Free;
end;


 
Marat ©   (2006-11-08 12:22) [3]

Спасибо большое! Помогло!



Страницы: 1 вся ветка

Текущий архив: 2006.11.26;
Скачать: CL | DM;

Наверх




Память: 0.44 MB
Время: 0.038 c
11-1139596592
rainstuff
2006-02-10 21:36
2006.11.26
MHTrackBar не работает в новых версиях KOL:(


2-1163061965
Greenchel
2006-11-09 11:46
2006.11.26
Лимит строк в RichEdit


2-1162832560
pathfinder
2006-11-06 20:02
2006.11.26
Запуск файла справки chm..


2-1163061812
yyy111
2006-11-09 11:43
2006.11.26
for i := ...


2-1162953204
Grademax
2006-11-08 05:33
2006.11.26
Как правильно убить процесс?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский