Raised This Month: $51 Target: $400
 12% 

[Ask] String[] ?


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-10-2014 , 20:56   Re: [Ask] String[] ?
Reply With Quote #11

Quote:
Originally Posted by ^SmileY View Post
EDIT:

new szName[] = "SmileY";

worked, but i do not know if it is a correct way, i think was created with a maximum lenght of 7 chars
That works because you are specifying an array size by giving it a string of finite length.
__________________
fysiks is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 03-11-2014 , 07:26   Re: [Ask] String[] ?
Reply With Quote #12

@Dias,
It depends on what you want to do, if you exactly know the String size ( like for const variables ) you can use Sting[] = "Some string" else you have to go with A. And one more things if you want to use A, you have to initialize the string there itself. If you state your purpose we can help you in a better way.

PHP Code:
new string[]; // <--- Perfectly INVALID
new string[] = "Dias"// <--- Perfectly Valid
new string[5] = "Dias"// Same as above 
For more information : Pawn Language Guide (Pg. No 67)

Edit : One extra element for null character.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 03-12-2014 at 04:03.
Shooting King is offline
Old 03-11-2014, 16:41
Black Rose
This message has been deleted by Black Rose. Reason: No longer a concern
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 03-12-2014 , 04:03   Re: [Ask] String[] ?
Reply With Quote #13

One extra element for null char :p
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here
Shooting King is offline
dias
BANNED
Join Date: Jul 2009
Location: South Vietnam
Old 03-12-2014 , 06:35   Re: [Ask] String[] ?
Reply With Quote #14

Ah i see, so they are same
dias is offline
Send a message via Yahoo to dias Send a message via Skype™ to dias
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-14-2014 , 01:21   Re: [Ask] String[] ?
Reply With Quote #15

Quote:
Originally Posted by dias View Post
Ah i see, so they are same
To what are you referring?
__________________
fysiks is offline
dias
BANNED
Join Date: Jul 2009
Location: South Vietnam
Old 03-14-2014 , 06:03   Re: [Ask] String[] ?
Reply With Quote #16

PHP Code:
new StringB[] = "String"
// same as
new StringA[6

Last edited by dias; 03-14-2014 at 07:27.
dias is offline
Send a message via Yahoo to dias Send a message via Skype™ to dias
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-15-2014 , 03:05   Re: [Ask] String[] ?
Reply With Quote #17

Quote:
Originally Posted by dias View Post
PHP Code:
new StringB[] = "String"
// same as
new StringA[6
NO!!!! You need 7 cells to store a string with 6 characters. You have to account for the null character.
__________________

Last edited by fysiks; 03-15-2014 at 03:05.
fysiks is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-15-2014 , 12:03   Re: [Ask] String[] ?
Reply With Quote #18

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.
__________________
Like my clean plugins and work?

Last edited by Baws; 03-15-2014 at 12:06.
Baws is offline
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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-15-2014 , 15:06   Re: [Ask] String[] ?
Reply With Quote #20

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
No! If you declare a string with 33 cells, it will contain 33 cells. It's not that hard. Arrays in Pawn are zero base so the last cell will be indexed by 32.
__________________
fysiks is offline
Old 03-15-2014, 18:11
Black Rose
This message has been deleted by Black Rose. Reason: fysiks is correct
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:21.


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