PDA

View Full Version : Count the numbers of symbols etc in a name



Ni3ls
13th December 2012, 16:02
Hi all,

Im new here. Some ppl may know me from modsonline or just COD2.
But how can you count the numbers of symbols, signs, numbers and letters on a name?
For example, Ni3ls = 5, but Ni^23^7ls = 8.

I need this, because when a name is longer then 10 characters for example, something will happen with that name.
Thanks

kung foo man
13th December 2012, 16:14
Yeah, i know you :D


Didnt tested, but shall work:



letters = 0;
numbers = 0;
symbols = 0;

for (i=0; i<str.size; i++)
{
switch (str[i]) // switch on current char
{
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
numbers++;
break;
case "^": // add all other symbols you want
symbols++;
break;
default:
letters++;
}
}

Ni3ls
13th December 2012, 16:44
I will test it later. But str.size is the size of the name right? Is it possible to get the stringsize then, since it's already implented in cod?

kung foo man
13th December 2012, 16:52
Yep, correct, like "test".size == 4

Ni3ls
13th December 2012, 19:16
Well it was just this what I was looking for.

self.name.size
Thanks to Izno. And ty kung for the other script, I can use that aswell ;)

Tally
14th December 2012, 13:25
Hi all,

Im new here. Some ppl may know me from modsonline or just COD2.
But how can you count the numbers of symbols, signs, numbers and letters on a name?
For example, Ni3ls = 5, but Ni^23^7ls = 8.

I need this, because when a name is longer then 10 characters for example, something will happen with that name.
Thanks


if( self.name.size > 10 )
doStuff();

Ni3ls
14th December 2012, 13:50
Yes i already got it ;)

BTW: kung str.size is undefined in ur script ;)

kung foo man
14th December 2012, 16:56
write before the script:


str = player.name;

Ni3ls
14th December 2012, 17:12
Danke sehr!