SA-MP Forums Archive
Copy a string to another string... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Copy a string to another string... (/showthread.php?tid=290045)



Copy a string to another string... - Whizion - 14.10.2011

I used to remember how to do this but i forgot...

How do i copy a string to another string?

string1 = string2; <-- this won't work

So please refresh my memory, thank you.


Re: Copy a string to another string... - Jack_Leslie - 14.10.2011

I think your looking for this:
https://sampwiki.blast.hk/wiki/Strmid


Re: Copy a string to another string... - Jefff - 14.10.2011

or
pawn Код:
format(string1,sizeof(string1),string2);
or
pawn Код:
strcat((string1[0]='\0',string1),string2);



Re: Copy a string to another string... - Whizion - 14.10.2011

Thanks all, i did it like this:

pawn Код:
strmid(password, PlayerInfo[playerid][pPass], 0, 32, 32);



Re: Copy a string to another string... - Jefff - 14.10.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
The first way "str2 = str1;" DOES work!

And Jeff: Don't EVER use format for this - it's horribly slow!
does work if size string1 == size string2 :P

and i dont use format for this but strcat or string1 = string2 ;p and I think its small difference between
format and strcat if i use it one time


Re: Copy a string to another string... - Incubator - 15.10.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
Its not a small difference - its very significant...
Oh crap, how slow is format?
I turned copying strings with format into a habit.


Re: Copy a string to another string... - Kush - 15.10.2011

Quote:
Originally Posted by Incubator
Посмотреть сообщение
Oh crap, how slow is format?
I turned copying strings with format into a habit.
It isn't the point of slow, assignment is the most logical thing you would do in this case.


Re: Copy a string to another string... - Incubator - 15.10.2011

What if the sizes aren't matching?


Re: Copy a string to another string... - Kush - 15.10.2011

Quote:
Originally Posted by Incubator
Посмотреть сообщение
What if the sizes aren't matching?
Then part of the text won't show.


Re: Copy a string to another string... - Incubator - 15.10.2011

Quote:
Originally Posted by Siin
Посмотреть сообщение
Then part of the text won't show.
No, it would generate a compiler error...