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

•  Animation Loaders  1 050

•  DeLiKaTeS Tetris (Тетрис)  5 984

•  TDictionary Custom Sort  7 920

•  Fast Watermark Sources  7 579

•  3D Designer  10 819

•  Sik Screen Capture  8 157

•  Patch Maker  8 345

•  Айболит (remote control)  8 396

•  ListBox Drag & Drop  7 251

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

•  Графические эффекты  8 453

•  Рисование по маске  7 818

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

•  Canvas Drawing  6 796

•  Рисование Луны  6 730

•  Поворот изображения  5 834

•  Рисование стержней  4 780

•  Paint on Shape  3 477

•  Генератор кроссвордов  4 493

•  Головоломка Paletto  3 618

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

•  Пазл Numbrix  2 859

•  Заборы и коммивояжеры  3 809

•  Игра HIP  2 578

•  Игра Go (Го)  2 593

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

•  Программа укладки плитки  2 402

•  Генератор лабиринта  3 154

•  Проверка числового ввода  2 637

•  HEX View  3 047

 
скрыть

  Форум  

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-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

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