MAP index

gpe

Member
Licensed User
Longtime User
I noticed that in MAP collection the member "indexOf" is missing.
Is there a way to find out the index related to the key other than searching among the items?
gp
 

gpe

Member
Licensed User
Longtime User
many thanks, Erel
I need to filter an array of strings where the key is inside and build a listview.
I'm not so sure, but creating a map using substrings doesn't work properly. This is the reason I wanted to use the index instead of keys.
Now I've solved the problem creating two arrays to correlate the indexes.
 

Hubert Brandel

Active Member
Licensed User
Longtime User
Is this a bug ?

Hi,

map keys are unique, this is true and usefull.
It works good with numeric keys, but I was confused on this:

B4X:
Dim m As Map
m.Initialize
m.Put("test","Testwert")
m.Put("TEST","New Value")
Log("Test=" &  m.Get("Test") ) ' => null
Log("test=" &  m.Get("test") ) ' => Testwert
Log("TEST=" &  m.Get("Test") ) ' => null

The seconds call - m.Put("TEST","New Value") - was ignored.
m.GET is case sensitive, thats not usefull.
PUT should build the key with key.tolower()
GET should build the key with key.equalignorecases()

Am I right ?

Does SQL needs fieldnames in lower ?
 

agraham

Expert
Licensed User
Longtime User
PUT should build the key with key.tolower()
GET should build the key with key.equalignorecases()

Am I right ?
No. A Map can hold any kind of Object for keys and values, not just Strings. A Map just tests for object identity, it knows nothing about what the actual keys and values are. If you are using string you will have to do your own case-conversion if you want case-insensitivity.
 

Hubert Brandel

Active Member
Licensed User
Longtime User
Hi,

@ Klaus,

you are right and found my mistake

B4X:
Dim m As Map
m.Initialize
m.Put("test","Testwert")
m.Put("TEST","New Value")
Log("Test=" &  m.Get("Test") ) ' => null
Log("test=" &  m.Get("test") ) ' => Testwert
Log("TEST=" &  m.Get("TEST") ) ' => "New Value"

@all

I find it very strange to have case sensitive variables and filenames. I can't see any serious reason why linux does it this way. A case insensitive
key would be much easier and avoid typing errors.
 

kickaha

Well-Known Member
Licensed User
Longtime User
Hi,
@all

I find it very strange to have case sensitive variables and filenames. I can't see any serious reason why linux does it this way. A case insensitive
key would be much easier and avoid typing errors.

Yes but it would not be as flexible (and therefore not as useful).
 
Top