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 / counting character

Author
Message
DarkBASIC Discussion
7
Years of Service
User Offline
Joined: 7th Jul 2013
Location:
Posted: 7th Jul 2013 18:56
does anyone know how to count words when using dbGetEntry. or is there any methods to count character in text when you're using Dark GDK?
HomerS
13
Years of Service
User Offline
Joined: 8th Apr 2007
Location:
Posted: 1st Sep 2013 23:15
count on your fingers, if it is less then 10...

Toedeledoki
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 2nd Sep 2013 09:35
Note that this is the DarkBASIC forums, not the GDK, so you might have trouble there. Regardless, as a GDK user, I will offer some help.

However, the easiest method would be through regular expressions. Note that only c++ 2011 has the library for regular expressions.

Alternatively, you can scan through the string using a for loop looking for a space or a newline character, like so:



Note that this assumes you are using std::string. If you are using the native GDK method of strings, it will involve an array of characters (char[length]) and you will need to find the length in another way (I'm sure GDK has a method for that). I may also have the wrong kind of quotes, so if that doesn't compile, try using " instead of '

Hope this helps!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Sep 2013 20:35
The only new threads we get on here now are wrong boards.



Formerly OBese87.
BN2 Productions
16
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 2nd Sep 2013 22:17
Quote: " The only new threads we get on here now are wrong boards. "


Sadly true. Probably because DBC is one of the only TGC products that doesn't have a free version (to my knowledge, at least)

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 4th Sep 2013 12:36 Edited at: 4th Sep 2013 12:41
Just jumping in here to provide my end of C++ knowledge. The standard library <algorithm> contains a count function accepting iterators.



If you're using C strings (const char*) like BN2 is saying, you can use std::count as well with a small modification:



OR you can create a temporary std::string object and use the first method:



Note that empty strings will still output a wordCount of 1, so it might be worth checking if characterCount is 0, and if so, set wordCount to 0.

TheComet

Login to post a reply

Server time is: 2020-08-13 18:29:06
Your offset time is: 2020-08-13 18:29:06