Arsip: Baca file text

more 20 years ago
pegal_linux
Bagaimana cara membaca file text dengan delphi 6. Dan bisa tahu berapa jumlah karakter yang ada dalam file. Kalau perlu dia bisa kasih informasi misalnya karakter ke-n didalam file text tersebut apa. Oya, bagaimana ya kita tau kalau pembacaan tersebut pindah baris....?
Sebelumnya terima kasih banyak atas bantuanya...

more 20 years ago
deLogic
Pertama, Anda buka dengan AssignFile dan Reset;
kemudian Anda pake ReadLn untuk baca satu baris teks (sekalian pindah baris), atau Read untuk baca satu karakter sampai EOF.
kalau untuk karakter ke n saya masih belum yakin bisa pake Seek karena Seek untuk untyped file.
jalan satu2 nya ya anggap aja file tersebut 'untyped file'...

more 20 years ago
ZeAL
kayaknya udah pernah ada yang nanya deh..anyway..
kalo baca..
var TFile : text;
dataperbaris : string;
assignFile(TFile,'c:\test.txt');
reset(TFile);
while not eof(Tfile) do
begin
readln(Tfile, dataperbaris);
showmessage(dataperbaris);
end;
CloseFile(TFile);
Gitu kira2.. (ini blon ditest, cuma seingetnya aja.. kalo salah.. harap maklum.. :D )
Kalo baca perhuruf, pakenya Read(Tfile, datapehuruf);
Kalo pengen tau posisi ke-n datanya apa, mungkin bisa ditampung dulu ke array.. pertama baca dulu panjang datanya di file, trus buat array dengan panjang data tersebut.. trus simpen datanya ke array tsbt sesuai dengan nomor index...
Tapi sayangnya kalo datanya besar, bisa beratzzzz abiezzzz...

more 20 years ago
meinardi
Cara lain yg paling enak pake TStringList
procedure bacafile;
var
ltemp : TStringList;
lstr : string; // mungkin kalo kurang besar kalo gak salah ada widestring
begin
ltemp := TStringList.Create;
ltemp.loadfromfile(c:\myfile.txt);
// utk baca baris ke n
showmessage(ltemp[n]);
// utk baca character ke n
lstr := ltemp.text;
messagebox('huruf ke n = ' + lstr[n]);
// ato yg ini, tp gak tau bisa jalan ato gak
messagebox('huruf ke n = ' + ltemp.text[n]);
ltemp.free;
end;
semoga membantu. Rasanya bisa jalan sih. :)

more 20 years ago
deLogic
saya kira memang trik ini cukup banyak membantu, apalagi kalo ingin menyimpan perubahan, list-nya bisa langsung di save...
kalau untuk menghitung seluruh jumlah karakter di dalamnya gunakan length(ltemp.text)

more 20 years ago
imunk
procedure bacafile; var ltemp : TStringList; lstr : string; // mungkin kalo kurang besar kalo gak salah ada widestring begin ltemp := TStringList.Create; ltemp.loadfromfile(c:\myfile.txt); // utk baca baris ke n showmessage(ltemp[n]); //error // utk baca character ke n lstr := ltemp.text; messagebox('huruf ke n = ' + lstr[n]); // ato yg ini, tp gak tau bisa jalan ato gak messagebox('huruf ke n = ' + ltemp.text[n]); ltemp.free; end;error - Undeclared identifier : 'n' --> saya tambah variabel n:byte; - muncul error : List index out of bound (80). kira 2 apa ya yang salah...?? :cry:

more 20 years ago
deLogic
nilai n belum diinisialisasi, n adalah baris yang ingin dibaca & biar lebih save, berikan n sebagai tipe integer.

more 20 years ago
cyber_hecker
gue gak ngerti ini nyambung atau enggak. tapi yang penting posting aja dulu.
wakakakka....
fungsi untuk menghitung total semua kata yang ada.
contoh program download disini

function TFMain.GetWordCount(stText : String): Integer;
const
// Define word separator types that we will recognise
LF =#10;
TAB =#9;
CR =#13;
BLANK =#32;
var
WordSeparatorSet : Set of Char; // We will set on only the above characters
index : Integer; // Used to scan along the string
inWord : Boolean; // Indicates whether we are in the middle of a word
stWordCount : Integer; // Internal count of words in the string
begin
// Turn on the TAB, CR, LF and BLANK characters in our word separator set
WordSeparatorSet := [LF, TAB, CR, BLANK];
// Start with 0 words
stWordCount := 0;
// Scan the string character by character looking for word separators
inWord := false;
for index := 1 to Length(stText) do
begin
// Have we found a separator character?
if stText[index] In WordSeparatorSet then begin
// Separator found - have we moved from a word?
if inWord then Inc(stWordCount); // Yes - we have ended another word
// Indicate that we are not in a word anymore
inWord := false;
end
else
// Separator not found - we are in a word
inWord := true;
end;
// Finally, were we still in a word at the end of the string?
// If so, we must add one to the word count since we did not
// meet a separator character.
if inWord then Inc(stWordCount);
Result := stWordCount;
end;[/code:1:140622a723]
fungsi untuk mencari posisi pertama dari kata tertentu.
function TFMain.FindFirst(search: String): Integer;
begin
// Here we sort of cheat - we save the search string and just call
// FindNext after setting the initial string start conditions
stFindPosition := 1;
Result := FindNext(Memo1.Lines.Text,search);
end;
fungsi untuk mencari posisi berikutnya dari kata tertentu.
[code:1:140622a723]function TFMain.FindNext(stText, stFindString: String): Integer;
var
Index : Integer;
FindSize : Integer;
begin
/// Only scan if we have a valid scan string
if Length(stFindString) = 0
then Result := -2
else
begin
// Set the search string size
FindSize := Length(stFindString);
// Set the result to the 'not found' value
Result := -1;
// Start the search from where we last left off
index := stFindPosition;
// Scan the string :
// We check for a match with the first character of the fromStr as we
// step along the string. Only when the first character matches do we
// compare the whole string. This is more efficient.
// We abort the loop if the string is found.
while (index <= Length(stText)) and (Result < 0) do
begin
// Check the first character of the search string
if stText[index] = stFindString[1] then
begin
// Now check the whole string - setting up a loop exit condition if
// the string matches
if MidStr(stText, index, findSize) = stFindString
then Result := index;
end;
// Move along the string
Inc(index);
end;
// Position the next search from where the above leaves off
// Notice that index gets incremented even with a successful match
stFindPosition := index
end;
// This subroutine will now exit with the established Result value
end;
hitung jumlah kata tertentu.
function TFMain.GetTextCount(stText, Search: String): Integer;
var
i : integer;
begin
i := 0;
if FindFirst(Search) > 0 then begin
Inc(i);
repeat
Inc(i);
until FindNext(stText,search) < 0;
end;
Result := i - 1;
end;
contoh hasil akhir :


more 19 years ago
imunk
thanks buat mas2 yang jago2 delphi, sedikitnya permasalahan saya bisa terbantu.
khusus buat mas cyber_hecker, tuh program tampilannya keren banget (tombolnya keren, hehe...), tapi waktu saya buka di kompi saya tampilannya biasa aja tuh....
saya pake wxp tapi dengan mode klasik, gimana ya cara bikin form kayak gitu..??
thanks... :)
more ...
- Pages:
- 1
- 2
reply |
Report Obsolete
AI Forward

🚀 We're thrilled to partner with Alibaba Cloud for "AI Forward - Alibaba Cloud Global Developer Summit 2025" in Jakarta! Join us and explore the future of AI. Register now:
https://int.alibabacloud.com/m/1000400772/
#AlibabaCloud #DeveloperSummit #Jakarta #AIFORWARD
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 5 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 5 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 13 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 13 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 13 years ago
Random Topic
- Coding bangkitkan himpunan data acak
by agnes in Tutorial & Community Project more 17 years ago - CAMERA : PENGENALAN WAJAH DI DELPHI
by ssarifin in Reporting more 15 years ago - MySQL server
by shee in Hal umum tentang Pascal Indonesia more 18 years ago - Manipulasi data menggunakan parameter
by asepolin in Hal umum tentang Pascal Indonesia more 16 years ago - bikin database lewat aplikasi delphi
by yayaretina in MySQL more 18 years ago - Cenderung yang Mana ?
by budi_bunga in OOT more 18 years ago - Italic or Underline
by umarbakri in OOT more 18 years ago - butuh saran untuk tugas kuliah aku
by R960XT in Enginering more 19 years ago - Run Delphi in Web ???
by jancky in Tip n Trik Pemrograman more 17 years ago - excel to dbgrid or the other...??
by adokonax in Tip n Trik Pemrograman more 18 years ago