How can I print string from number index to end?
#1

Hello guys, how can I print string from cell what I want to to string end?

H E L L O W O R L D
0 1 3 4 5 6 7 8 9 10 11

Then I want to output only "World",

printf("%s", string[6]);
not working for me.

Thankls
Reply
#2

pawn Код:
new string[6] = "World";
printf("%d", string[0]);
Reply
#3

It outputs me ascii of 'W'
Reply
#4

I don't really understand what you want. If you just print the whole string:
pawn Код:
print(string);
Using an index and %s placeholder will print all the characters from that index until the end of string.
Using an index and %i or %d placeholder will print numbers.
Reply
#5

I want to print part of string.
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
...
Using an index and %s placeholder will print all the characters from that index until the end of string.
...
Let's say you want to print the last 3 characters of it:
pawn Код:
printf("%s", string[2]);
// string contains "World" and it will print "rld".
If the part of the string is at the beginning, then extract it: https://sampwiki.blast.hk/wiki/Strmid
Reply
#7

Thanks, it works. :P
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)