FindMapElement and #PB_String_NoCase

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

FindMapElement and #PB_String_NoCase

Post by Seymour Clufley »

I think this would be useful.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: FindMapElement and #PB_String_NoCase

Post by Trond »

Why don't you make all elements lowercase and then use findmapelement(map(), lcase(string))?
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: FindMapElement and #PB_String_NoCase

Post by Seymour Clufley »

Trond wrote:Why don't you make all elements lowercase and then use findmapelement(map(), lcase(string))?
Well yes, that would be one solution. But I think #PB_String_NoCase would be easier to code, and would bring that command in line with FindString().
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: FindMapElement and #PB_String_NoCase

Post by STARGÅTE »

but the problem ist:

Code: Select all

NewMap Test.i()

Test("Case") = 1
Test("casE") = 2

Debug Test("Case")
Debug Test("casE")

FindMapElement(Test(), "case", #PB_String_NoCase)
which element is now to be found?
Case ?
casE ?
or none Element, because it is not unique ?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: FindMapElement and #PB_String_NoCase

Post by Seymour Clufley »

That would be for Fred/Freak to decide.

I would suggest the first element that is found. If the programmer is using #PB_String_NoCase he should be aware if there could be multiple matching elements in the map and it's a risk he can choose to take.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: FindMapElement and #PB_String_NoCase

Post by Rescator »

A #PB_String_NoCase would also slow down the hash map a lot, in fact it might be almost as fast to just use a list I suspect.
Post Reply