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 / Finding 'Words' inside a string. !Need Help! newb question

Author
Message
Brent_Seraphim
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: United States
Posted: 28th Dec 2002 06:35
Ok, I've looked everywhere scanned over many a doc, function library and help file but to no avial. Lets say I had a string:
TempChar_Helmet$ = "Dingy New York Yankee's Baseball Cap"

What function or syntax would I use to deteremine if the word 'Dingy' was in the String TempChar_Helmet$?
"Laugh to scorn the power of man..."
HAL
21
Years of Service
User Offline
Joined: 28th Aug 2002
Location:
Posted: 28th Dec 2002 18:31
i don't know if their's a function for it, but you could just use something simple like this:

TempChar_Helmet$ = " New York Yankee's Dingy Baseball Cap "
findString$="Dingy"
stringLenght=len(TempChar_Helmet$)
for a=0 to stringLenght
s0$=mid$(TempChar_Helmet$,a)
s1$=mid$(TempChar_Helmet$,a+1)
s2$=mid$(TempChar_Helmet$,a+2)
s3$=mid$(TempChar_Helmet$,a+3)
s4$=mid$(TempChar_Helmet$,a+4)
match$=s0$+s1$+s2$+s3$+s4$
if match$=findString$ then print:print "match found!"
print mid$(TempChar_Helmet$,a);
wait 500
next stringLenght
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 28th Dec 2002 18:58
What you're looking for is an InStr function. A command that is curiously missing in DarkBasic, although present in most other BASIC languages.



example:
print InStr("Dingy New York Yankee's Baseball Cap", "Dingy", 1, 0)

Will return the position of the check word within string or 0 if not present.

"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Easily Confused
21
Years of Service
User Offline
Joined: 22nd Oct 2002
Location: U.K. Earth. (turn right at Venus)
Posted: 28th Dec 2002 19:06
...I forgot something, depending on what version of DarkBasic you have, you may need this alternative version.




"Earth is the cradle of humanity,
but one cannot live in a cradle forever"
Konstantin E. Tsiolkovsky (1911)
Brent_Seraphim
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: United States
Posted: 28th Dec 2002 21:50
Thanks everybody Rock on!

"Laugh to scorn the power of man..."

Login to post a reply

Server time is: 2024-04-26 09:25:50
Your offset time is: 2024-04-26 09:25:50