AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get number of word in text??? (https://forums.alliedmods.net/showthread.php?t=51855)

amxxn00b 02-25-2007 05:28

How to get number of word in text???
 
I have text:
new arg[128] = "Hello World, this is I!"
number of words in text is: 5
Hello - 1st
World, - 2nd
this - 3rd
is -4th
I! - 5th

and how to get this number(5) in amxx???

VEN 03-05-2007 13:18

Re: How to get number of word in text???
 
There are strbreak, strtok and parse functions (see string.inc or function reference for details/examples).

[ --<-@ ] Black Rose 03-05-2007 18:27

Re: How to get number of word in text???
 
Code:
count_words(text[]) {     new len, pos, words     len = strlen(text) + 1         while ( len-- != 0 && text[len] == ' ' ) { }         while ( pos <= len ) {         if ( text[pos] == ' ' && lastchar != ' ' && lastchar != 0 )             words++                 lastchar = text[pos]     }     return words }


All times are GMT -4. The time now is 20:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.