AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   String lengh issue (https://forums.alliedmods.net/showthread.php?t=140777)

#8 SickneSS 10-16-2010 12:42

String lengh issue
 
I want to know how much characters are in use in a string but with not passing str_to_num.

Example :
Code:
new name[32]; if(name > 31) /* Or something like that */
Because I want to copy name (String) to an new array.

dFF 10-16-2010 12:51

Re: String lengh issue
 
strlen( x )

if( strlen( name) > 31 )

Kreation 10-16-2010 13:56

Re: String lengh issue
 
Quote:

Originally Posted by dFF (Post 1326504)
strlen( x )

if( strlen( name > 31 ) )

Code:
if( strlen( name ) > 31 )

#8 SickneSS 10-17-2010 02:48

Re: String lengh issue
 
Doesn't work:s

fysiks 10-17-2010 03:04

Re: String lengh issue
 
Tell us specifically what you are doing

Quote:

Originally Posted by #8 SickneSS (Post 1326494)
Because I want to copy name (String) to an new array.

According to this statement all you need is to use copy().

#8 SickneSS 10-17-2010 05:48

Re: String lengh issue
 
Quote:

Originally Posted by fysiks (Post 1327119)
Tell us specifically what you are doing



According to this statement all you need is to use copy().

Yes but I must check the lengh of the string,because if the player tipes more than 32 lenght,this will be show an print and will give one more chance to the player.

Hunter-Digital 10-17-2010 06:05

Re: String lengh issue
 
If you must check the length of some string use strlen()
If you want something to be copied to something else, just use copy, don't freaking worry about lenghts because copy requires a length parameter of the string you're writing to so basically, it's failproof.

issen1 10-17-2010 06:24

Re: String lengh issue
 
Quote:

Originally Posted by Hunter-Digital (Post 1327227)
If you must check the length of some string use strlen()
If you want something to be copied to something else, just use copy, don't freaking worry about lenghts because copy requires a length parameter of the string you're writing to so basically, it's failproof.

He's trying to save a message by a player from the server and if the player's message exceeds the maximum length for his array, he wants to ask the player to enter a new message.

strlen is what you are looking for. What do you mean with "It doesn't work" ?

#8 SickneSS 10-17-2010 06:26

Re: String lengh issue
 
I tried the wat of Kreation and dFF and didn't work:s

issen1 10-17-2010 06:29

Re: String lengh issue
 
Quote:

Originally Posted by #8 SickneSS (Post 1327250)
I tried the wat of Kreation and dFF and didn't work:s

The code of dFF was wrong, but the code of Kreation should work. Show some more code because your mistake is somewhere else.


All times are GMT -4. The time now is 10:23.

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