Strings and integers

I have a list of strings, TStringList seems like a reasonable place to store them and I can get them back out via Stings[i]. Now I want an integer to go with each string. So I put it in Values[i]. Now my Strings[i] looks like "0=140". So I put my string in Name[i] and it throws an exception back at me because it has a space in it or something. So, I just want to know, forget most of what I just said, and tell me how to store a string and an integer, someone PLEASE!

Extremely frustrated now,
Pete

Comments

  • [color=Blue]If the string and integer are both complete some kind of structure, then simply use vector of structures.[/color]
  • So there is no way to use a TStringList if you want an integer associated with each string. Is there an equivalent of TStringList (in Borland C++ Builder 6 that is) which holds integers rather than strings?
  • [color=Blue]Pack it into text using some kind of separator which can't be found in text, like: "62353|my text here". Then simply extract both values:[/color]
    [code]
    char* s = "62353|my text here";
    int n = atoi (s);
    char* text = strchr (s, '|') + 1;
    [/code]
    [color=Blue]But that would be slower then just a structure.[/color]
  • That's almost exactly what they came from, I store them like that in the system registry. Never mind, thanks for trying. C++ is a bit rubbish, isn't it? ;-)
  • Ah, I just stumbled on it (although I've been doing other stuff, I've been looking for this for two months, before it got urgent):

    [code]
    TList *pTest;
    int nTest;

    pTest = new TList();
    pTest->Add((void *)5);
    pTest->Add((void *)4);
    nTest = (int)pTest->Items[1];
    nTest = (int)pTest->Items[0];
    [/code]

    Simple? Yes.
    Easy to find? No.
    Are you happy yet? Yes.

    Pete

  • [color=Blue]Slow? YESSSSSSSSS!!!!!!!!![/color]
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories