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.

DarkBASIC Discussion / check for word

Author
Message
Cookyzue
21
Years of Service
User Offline
Joined: 12th Oct 2003
Location: Who Cares?!
Posted: 9th Jan 2004 02:20
im using the input command and i what it so you can check if there is a certain word in a sentenc the user wrote.i used if a$= "the" then print "5" but that only works if that is the only word the user types.Can anyone help?thnaks
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 9th Jan 2004 05:00
Ok... you have to parse the string.

What you have to do is do a few nested loops, checking for spaces, ( " " ) then, when a space is found for the first time, everythign before that is the first word

Then, in the next loop, you check for the next space. when it is found, everything between the last space and this one is the next word, and so on.

To chsck for spaces etc, use the Mid$() command.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Macabre
21
Years of Service
User Offline
Joined: 15th Jan 2004
Location:
Posted: 16th Jan 2004 04:15
hmmm no instr$ funktion in db ...to bad
so yes youre stuck with the LEN() and MID$() commands
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2004 07:51 Edited at: 16th Jan 2004 07:52
I just wrote a substring method in one of my other posts.
http://darkbasicpro.thegamecreators.com/?m=forum_view&t=23917&b=6

Eh, screw it! Here, I'll write it for you since I'm in the mood to code stuff. There's an instr$() function now!

"eureka" - Archimedes
Cookyzue
21
Years of Service
User Offline
Joined: 12th Oct 2003
Location: Who Cares?!
Posted: 23rd Jan 2004 02:51
thats for db pro though Thanks anyway
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Jan 2004 09:49
Now it works with DBC, just checked. All I had to change was the function header.

"eureka" - Archimedes
Cookyzue
21
Years of Service
User Offline
Joined: 12th Oct 2003
Location: Who Cares?!
Posted: 24th Jan 2004 01:06
thanks
The Dream Keeper!
21
Years of Service
User Offline
Joined: 9th Oct 2003
Location: Netherlands! HOLLAND!
Posted: 24th Jan 2004 10:47
Actually, I tried your code Phaelax but.. it didn't work with me. I got this:
Quote: "runtime error at line 17. Program ran into a function declaration at line 17"


But as I remember.. I've made an surch program that surch for a word in a string. I'll should edit it and post it here. Hope i can find it.

Bring fun to life!!!!!
The Dream Keeper!
21
Years of Service
User Offline
Joined: 9th Oct 2003
Location: Netherlands! HOLLAND!
Posted: 24th Jan 2004 11:35
Allright.. i didn't found it.. but i wrote you a new one. It workes great with me and it's fully commended. Every command has an explination. Hope you will enjoy it. Feel free to use. (for DBC)

Hope i've helped,

The Dream Keeper!

Bring fun to life!!!!!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Jan 2004 15:19
Mine worked fine for me in dbc 1.13. whats your version?

"eureka" - Archimedes
The Dream Keeper!
21
Years of Service
User Offline
Joined: 9th Oct 2003
Location: Netherlands! HOLLAND!
Posted: 24th Jan 2004 20:36
DBC 1.13

Bring fun to life!!!!!

Login to post a reply

Server time is: 2025-05-22 12:25:57
Your offset time is: 2025-05-22 12:25:57