Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Storing set/series of number in a field
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01543783
Message ID:
01543798
Views:
33
>>>>>>Hi,
>>>>>>
>>>>>>I need to store a series of numbers into a field (e.g. 1, 34, 22, 33, 3333, 7 and so on) so that later in the program it can be determined if a certain number is present in this "array" of numbers. Originally I was creating an array (based on this series of numbers), converting the array into a string, storing the string in a memo field; then retrieving the string and converting it to array. Now I am thinking that maybe there is a more efficient way. What if I store this series of numbers as a string of this type:
>>>>>>"1,34,22,33,3333,7" (basically converting each number into a string and then concatenating them). How would I then find out if a certain number (e.g. 3) is in the list? Using AT() will not give me the right result since character "3" is in the string but not the number 3. Anybody can suggest a more efficient method of storing this series of number and comparing them?
>>>>>>
>>>>>>TIA.
>>>>>
>>>>>You can search for ',' + Number + ',' in the ',' + String + ','
>>>>>
>>>>>This way AT will work correctly.
>>>>
>>>>I am thinking that I can store the numbers as the following
>>>>
>>>>"'1''34''22''33'" That is, each number enclosed with single quote. No commas. Then I can search with AT for '99'. It should be just as fast.
>>>
>>>If you do this, don't forget to prepend and append delimiters to the search term and
>>>the search string, e.g. --
>>>
>>>',' + searchterm + ',' $ ',' + delimited string + ',' && Naomi's comma-delimited suggestion
>>>
>>>-- (or the AT() equivalent, of course),
>>>where searchterm is the numeric converted to string.
>>>
>>>-m.
>>
>>I cannot see why I need to pre-fix and append delimiters; other than the single quote I am going to put before and after the number converted to a string. This way if I am looking for a number 33 in the string of numbers I will do the following:
>>
>>
>>cString = "'1''34''22''33'"   && note that the very first and the very last characters are double quotes. The rest are 
>>                                        && single quotes.
>>if at( '33', cString) > 0
>>   *-- exist
>>else 
>>  *-- does not exist
>>endif 
>>
>>
>>Thank you.
>
>This should also work, but you're storing a bit more info than with the comma-delimited list, which is easier to look at, IMHO.

The problem with a comman is that I would have to "think/consider" if the string has first and last comma. Using single quotes around the number makes is easier, IMHO :).
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform