Converting array elements into a string
BlitzMax Forums/BlitzMax Beginners Area/Converting array elements into a string
| ||
Afternoon all, and Happy Easter! I'm still working on my 'mini' word game, and would like some advice on the following. I have an array of 30 elements, each of which can contain a letter. So, if the player has picked the following letters: B L I T Z The array would be: 1-B 2-L 3-I 4-T 5-Z 6 to 30-"" How could I then take this, and then 'concatenate' the values into a variable, so, instead of the individual elements, I'd have: WORD="BLITZ" I can then check this against a dictionary I have to see if it is a valid word... ;) Many thanks, M |
| ||
why not use INSTR to check whether the given word is in the dictionary? |
| ||
Hiya, I will be doing that ultimately, but it's getting my individual letters into a string that I'm struggling with. Hope that's clear... ;) Cheers |
| ||
a:String = "" For Local temp:String = EachIn array a:+ temp Next |
| ||
Ah! Stingly simple! Many thanks, will implement it now! Cheers! |
| ||
arf, check, didn't read the Q too well :P |
| ||
No probs. ;) Although now, I am having problems with checking if the word is in my dictionary. The dictionary has 216552 entries in it, and I've tried a For...Next... loop, but to no avail. Variables I have: DIC[216552] - Array with all words present (dictionary) WORDSTRING - The word I wish to check if it is in the dictionary. I tried: For b=0 To 216552 If WORDSTRING=DIC[b] Then *** do stuff here *** WORDSTRING="" End If Next but it didn't play ball... :( Any ideas? :) |
| ||
omg, you really want to check over 200.000 words, each time you need to check? :D |
| ||
I don't want to have to, but can't think of any other way? :( I did get something similar working in B3D, and it didn't take any time at all using a similar sort of method. ;) Any other suggestions? |
| ||
Look up TMap in the documentation. If you use one to hold your dictionary, it will speed things up no end, and make things a little easier as well. |
| ||
Is TMap always fast? I'm not entirely sure how it works, but does it internally run through the whole given data to find a match? Is there a best-case and worst-case scenario with TMap? |
| ||
Hmm, not encountered TMap yet, will take a look. Many thanks, M. |
| ||
Is TMap always fast? I'm not entirely sure how it works, but does it internally run through the whole given data to find a match? It's a binary tree internally, I think. So a search through it is a binary search. It's always fast if you have a lot of data to search through which can be sorted on a key, yeah. Of course, it takes longer to insert and remove items because they have to be inserted to the correct place in the map. But in a dictionary, you don't remove and insert words very often, if at all, so there's no downside. |
| ||
The dictionary will be 'fixed' so once it's loaded into the 'tree' or 'list' it'll not change during execution. :) |
| ||
...and translate everything to lowercase when you do checks in case you're checking "Rabbit" with "rabbit" |
| ||
Is TMap always fast? No. It depends on how you use it. It's implemented as a Red-Black Tree. If you want the fastest possible lookup, you should go for a Radix Tree like say, a Patricia Tree.As far as I can tell though, nobody has so far made such a data structure in BlitzMAX. Could be wrong tho' so it probably wouldn't hurt to search the Code Archives for Radix. |
| ||
Maybe this will help and this too? |