Converting array elements into a string

BlitzMax Forums/BlitzMax Beginners Area/Converting array elements into a string

Matt Vinyl(Posted 2007) [#1]
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


CS_TBL(Posted 2007) [#2]
why not use INSTR to check whether the given word is in the dictionary?


Matt Vinyl(Posted 2007) [#3]
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


FlameDuck(Posted 2007) [#4]
a:String = ""
For Local temp:String = EachIn array
	a:+ temp
Next



Matt Vinyl(Posted 2007) [#5]
Ah! Stingly simple! Many thanks, will implement it now!

Cheers!


CS_TBL(Posted 2007) [#6]
arf, check, didn't read the Q too well :P


Matt Vinyl(Posted 2007) [#7]
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?

:)


CS_TBL(Posted 2007) [#8]
omg, you really want to check over 200.000 words, each time you need to check? :D


Matt Vinyl(Posted 2007) [#9]
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?


Gabriel(Posted 2007) [#10]
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.


CS_TBL(Posted 2007) [#11]
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?


Matt Vinyl(Posted 2007) [#12]
Hmm, not encountered TMap yet, will take a look. Many thanks, M.


Gabriel(Posted 2007) [#13]
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.


Matt Vinyl(Posted 2007) [#14]
The dictionary will be 'fixed' so once it's loaded into the 'tree' or 'list' it'll not change during execution. :)


tonyg(Posted 2007) [#15]
...and translate everything to lowercase when you do checks in case you're checking "Rabbit" with "rabbit"


FlameDuck(Posted 2007) [#16]
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.


Yan(Posted 2007) [#17]
Maybe this will help and this too?