Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File lines loaded in ListBox

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Hey all out here!!
I have got a problem with a test program I am writeing.
This program is to load a file into a ListBox which I cal FileIndex
Each line in the file is written to a line in FileIndex
So far I got the program to write as it is supposed to
however, in the end of each line it writes a symbol that loks like this []
I suppose it is a rowBreak(or somthing like it).
Is there a way to exclude this sign?

void __fastcall TForm1::Button1Click(TObject *Sender)
{/*
switch(MessageBox(Handle,(AnsiString("OK to erase and load new file?")).c_str(), "Load new file...",MB_OKCANCEL | MB_ICONHAND))
{
case ID_CANCEL : Abort(); // Ignore this part is is not a vital code
}*/

FileIndex->Items->Clear(); // Clear all lines
if(OpenDialog->Execute()) // Select a file
{
FILE *f;
char rows[82];
AnsiString line,name,value;
name=OpenDialog->FileName;
f=fopen(name.c_str(),"r"); // open file
while(fgets(rows,81,f)) // Parts of this code I got
{ // from an other guy, I just
line=(AnsiString)rows; // made it suit my purpose
int max = strlen(line.c_str()); // get length of row
value=line.SubString(0,max);
FileIndex->Items->Add(line); // Write file line to FileIndex, the ListBox
}
}
}

Thanks for any help!!

Martin!!
 
How do I TrimRight/Left?? Never heard about it!
 
801119,

[tab]TrimRight and TrimLeft are AnsiString methods. The will trim spaces and control characters from AnsiString variables. Of course, you could just use Trim[i/] which trims both left and right of the string. For example,

value = value.Trim();


[tab]Question, why didn't you just do int max = line.Length(); // get length of row instead of int max = strlen(line.c_str()); // get length of row?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top