Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 804

•  TDictionary Custom Sort  5 914

•  Fast Watermark Sources  5 715

•  3D Designer  8 490

•  Sik Screen Capture  6 051

•  Patch Maker  6 494

•  Айболит (remote control)  6 485

•  ListBox Drag & Drop  5 349

•  Доска для игры Реверси  95 015

•  Графические эффекты  6 689

•  Рисование по маске  5 819

•  Перетаскивание изображений  4 873

•  Canvas Drawing  5 246

•  Рисование Луны  4 970

•  Поворот изображения  4 517

•  Рисование стержней  3 195

•  Paint on Shape  2 442

•  Генератор кроссвордов  3 314

•  Головоломка Paletto  2 626

•  Теорема Монжа об окружностях  3 416

•  Пазл Numbrix  2 255

•  Заборы и коммивояжеры  2 914

•  Игра HIP  1 883

•  Игра Go (Го)  1 800

•  Симулятор лифта  2 138

•  Программа укладки плитки  1 864

•  Генератор лабиринта  2 304

•  Проверка числового ввода  1 991

•  HEX View  2 301

•  Физический маятник  1 962

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Импорт большого CSV файла



Скачивание файла.
Размер: неизвестно (скачено 45%).


var s: String; f: TextFile;
AssignFile(f, 'D:\\INPUT.TXT);
Reset(f);
while not EOF(f) do
  begin
   ReadLn(s, f);
   ShowMessage(GetField(s, 1));  {The first field\}
   ShowMessage(GetField(s, 6));  {The sixth field\}
   ShowMessage(GetField(s, 25)); {will return '' if no 25 column...\}
  end;
CloseFile(f);

{ ==== This function will return a field from a delimited string. ==== \}
function GetField(InpString: String; fieldpos: Integer): String;
var
  c: Char;
  curpos, i: Integer;
begin
  curpos := 1;
  for i := 1 to fieldpos do
    begin
     result := ''; if curpos > Length(InpString) then Break;
     repeat
       c := InpString[curpos]; Inc(curpos, 1);
       if (c = '"') or (c = #13) or (c = #10) then c := ' ';
       if c <> ',' then result := result + c;
       until (c = ',') or (curpos > Length(InpString))
    end;
  if (curpos > Length(InpString)) and (i < fieldpos) then result := '';
  result := Trim(result);
end;

{ ==== This function will trim a string removing spaces etc. ==== \}
function Trim(inp_str: String): String;
var
  i: Integer;
begin
  for i := 1 to Length(inp_str) do if inp_str[i] <> ' ' then Break;
  if i > 1 then Delete(inp_str, 1, i - 1);
  for i := Length(inp_str) downto 1 do if inp_str[i] <> ' ' then Break;
  if i < Length(inp_str) then Delete(inp_str, i + 1, Length(inp_str));
  result := inp_str;
  if result = ' ' then result := '';
end;





Похожие по теме исходники

Разбиение файла на части

Текст внутри файла




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте