Copy a string to another string...
#1

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.
Reply
#2

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

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

Thanks all, i did it like this:

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

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
Reply
#6

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.
Reply
#7

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.
Reply
#8

What if the sizes aren't matching?
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)