Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How To Get Text String On 1 Line From MemBlock?

Author
Message
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 3rd Jan 2018 13:58
Hi,

Working on the word dictionary lookup.
Lets say I have the following TXT file:
______________________________________________________
aaas
aaal
aaa
aaberg
aachen
______________________________________________________

If I use the following code:

it won't work correctly because "aaas" contains "aaa"...

How would I properly read one string line from a MemBock?
Hope someone can help, have much more work to do on this game soon!
JeZxLee
16BitSoft
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit Project!
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 3rd Jan 2018 14:25 Edited at: 3rd Jan 2018 14:47
Some ideas:

You could ensure your dictionary is ordered correctly... shorter words first then your existing code would work ok.

Alternatively - You could search for oneWordIndex = FindString( DictionaryString[0], "aaa" + "\n", 1, 1 )
("\n" is added above so it checks that the word ends)
You may need to use "\r" depending on what system you created the text file

Otherwise, you could write a Findstring alternative that compares letters and also checks for a or line return at the end

Also check out....
https://www.appgamekit.com/documentation/Reference/Core/GetStringToken.htm

and the GetStringToken2 as these do something similar to what your after!!
puzzler2018
User Banned
Posted: 3rd Jan 2018 18:01 Edited at: 3rd Jan 2018 18:01
or

findstring$="aaa"

if ( len( findstring$ ) = len(dictionarystring[0]) and (mid(dictionarystring [0],1,len(findstring)) = findstring$)
// Found
else
// Move to check the next word
endif
puzzler2018
User Banned
Posted: 3rd Jan 2018 18:10
Like this



JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 3rd Jan 2018 19:22
Thanks puzzler2018,

I got it all working now, but will revisit it before official Beta1 release to optimize.
Thanks again for your help with this project...
JeZxLee
16BitSoft
Video Game Design Studio
http://www.16BitSoft.com
Open-Source AppGameKit Project!
puzzler2018
User Banned
Posted: 3rd Jan 2018 19:27
No probs,
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Jan 2018 21:24
Isn't there a newline character after each word? If reading the text file into a memblock keeps those, you could add that to your search term.



oneWordIndex = FindString( DictionaryString[0], "aaa"+chr(10), 1, 1 )
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
puzzler2018
User Banned
Posted: 3rd Jan 2018 22:23
Great tip. as long as the FindString command in itself is really fast - cause just tried and its agonizingly slow searching a full length of words using my own version of a word find

Suppose this is all about optimisation now



Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Jan 2018 09:15
Phaelax wrote: "oneWordIndex = FindString( DictionaryString[0], "aaa"+chr(10), 1, 1 )"

Its the same suggestion I posted above in the second post. lol

Ben wrote: "Alternatively - You could search for oneWordIndex = FindString( DictionaryString[0], "aaa" + "\n", 1, 1 )"

chr(10) = "\n" - either way its checking for the newline character


You could optimise by splitting the dictionary up further, so its not having to findstring in such large chunks. Split A into AA, AB, AC,AD words and so the search is on a smaller string but this would require you to split up your dictionary string into substrings.




Login to post a reply

Server time is: 2024-11-24 04:49:19
Your offset time is: 2024-11-24 04:49:19