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 Professional Discussion / Detecting a certain character in a string?

Author
Message
Mudbud Productions
15
Years of Service
User Offline
Joined: 1st May 2011
Location: Cloud 9
Posted: 8th Jun 2011 05:37
Hey guys,
I am making a really cool function (CLASSIFIED!) but I was wondering if there is a possibility for DBPro to detect a special character in a string like a . or a , and after that it would do stuff... Is this possible? if so, how?

Silence is golden but duck tape is silver - Anonymous
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th Jun 2011 05:52
You could use LEFT$(), MID$() but not sure if there's an INSTR function though.

Warning! May contain Nuts!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 8th Jun 2011 07:09 Edited at: 8th Jun 2011 07:10
Yeah MID$() would work.



Or the quick way using IanMs FIND CHAR() command that doesn't need a FOR/NEXT loop.



Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 8th Jun 2011 08:15 Edited at: 8th Jun 2011 08:19
You can also use

FIND FIRST CHAR$()

and

FIND SUB STRING$()

If either of those returns a result greater than zero, you have found the character.

Using Grog's example...



BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jun 2011 09:28
I have INSTR, but I don't know which plugin it's from. It returns the position of the character, or 0 if not found.

x = instr(MyString,".",fromPos)

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 8th Jun 2011 17:30
INSTR() is also one of IanMs commands.

Mudbud Productions
15
Years of Service
User Offline
Joined: 1st May 2011
Location: Cloud 9
Posted: 8th Jun 2011 18:47
ok thanks, I will also look into the INSTR() thing.

Silence is golden but duck tape is silver - Anonymous
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jun 2011 19:59
Here's my instr() function I wrote waaay back in 2004.

http://forum.thegamecreators.com/?m=forum_view&t=23931&b=6

I've had to write all sorts of string commands over the years.

Login to post a reply

Server time is: 2026-07-10 22:54:56
Your offset time is: 2026-07-10 22:54:56