Thread: Familiar with AnsiString??

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    Question Familiar with AnsiString??

    sorry i'm posting alot but you people are smart...

    anywayz..


    i've got an array:

    AnsiString title[50];

    and i eventually add values to the different indexs of the array.

    for example

    title[0] = "Bob";
    title[1] = "Joe";
    title[3] = "Skip";

    now i don't fill up the last 46 slots or so...

    when i goto do a while loop for saving data to a file it does a forever loop causing my program to loop constantly.(which obviously isn't good)

    x = 0;
    while (title[x] != Null)
    {
    file << title[x];
    x = x + 1;
    }

    I've done a little reading and testing but i can't quite figure out the problem. I'm thinking that AnsiStrings that are empty aren't Null. And thats my problem i don't know what they are..Wouldn't title[x].c_str(); add null to end? or something i really don't know i'm lost..

    ive tried:

    x = 0;
    while (title[x] != "")
    {
    file << title[x].c_str();
    x = x + 1;
    }

    and

    x = 0;
    while (title[x] != " ")
    {
    file << title[x].c_str();
    x = x + 1;
    }

    and

    x = 0;
    while (title[x].c_str() != Null)
    {
    file << title[x].c_str();
    x = x + 1;
    }

    but always a forever loop. I've noticed NullStr(); function which i think i may need but i can't figure out how to use it.. the

    file << title[x].c_str();

    part works so my only problem is the while loop. Any help would be greatly appreciated

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    I assume you use Builder.

    A solution is a collection called TStringList:

    Code:
    TStringList *stringlist = new TStringList();
    stringlist->Add("1");
    stringlist->Add("2");
    stringlist->Add("3");
    stringlist->Add("4");
    for(int n = 0; n < stringlist->Count; n++)
    {
        Application->MessageBox(stringlist->Strings[n].c_str(), "", MB_OK);
    }
    delete stringlist;
    Also, you don't need to worry about the size of the StringList, as u have to do with an array.

  3. #3
    Unregistered
    Guest
    A couple other solutions would be:

    look up the AnsiString class to see if it has a member function looking for empty strings, like isEmpty() or empty().

    initialize all strings in the array to a given value using a loop. compare each string to the default. If current string is not default value, then do whatever. I believe that "" or "\0" will create an empty string if AnsiStrings are not "empty" by default.

    keep an index/counter variable equal to last index used in the array, or number of strings in the array, and use that to stop loop.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    thnx

    cool....thnx for both those i'll try em both out......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I dont know if your familiar with circlemud but..
    By errigour in forum C Programming
    Replies: 0
    Last Post: 03-25-2009, 05:27 AM
  2. AnsiString to char (BCPPB 5.0)
    By MiraX33 in forum C++ Programming
    Replies: 2
    Last Post: 09-01-2005, 11:48 AM
  3. AnsiString versus char *
    By Zahl in forum C++ Programming
    Replies: 35
    Last Post: 10-16-2002, 08:38 PM
  4. How do I play an MP3?
    By Hunter2 in forum Windows Programming
    Replies: 28
    Last Post: 05-20-2002, 08:49 PM
  5. AnsiString
    By golfinguy4 in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2002, 06:35 PM