View Single Post
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-15-2014 , 12:42   Re: [Ask] String[] ?
Reply With Quote #19

Quote:
Originally Posted by baws View Post
A string always uses the number under the number you used in it.
For example:
PHP Code:
new String[33
It will use:
PHP Code:
[32
I don't know if you get what i mean. But that's how it works ^

Another example:
PHP Code:
new String "Baws"
It will be:
PHP Code:
new String[5
I always use a im-pair number when i set a new string as it will use the pair one and so on.
All cells are used. The last cell is filled with null (0).
This is to let natives know where to stop reading the string. If null was not used we would have to define the length to be read for ALL NATIVES.
Code:
server_print("Test", 4); replace(Text, charsmax(Text), "Hello", 5, "What?", 5);
If null is missing there's a possibility that it will continue to read memory and you end up with something completely different from what you expected.

Like this:
Code:
    new test1[] = { 'T', 'e', 's', 't', '1' };     new test2[] = { 'T', 'e', 's', 't', '2' };     server_print("%s", test1);     server_print("%s", test2);
Code:
Test1
Test2Test1
__________________

Last edited by Black Rose; 03-15-2014 at 12:43.
Black Rose is offline