Split string on a specific length - 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: Split string on a specific length (
/showthread.php?tid=323346)
Split string on a specific length - T0pAz - 05.03.2012
How to split a string on a specific length without the usage of sscanf? For Instance:
pawn Код:
new sampletext[64] = "This is a sample text which will be splited into arrays";
new arrayofstr[2][128];
strsplit(sampletext, 27, arrayofstr);
printf("%s", arrayofstr[0]); // which will print out "This is a sample text which"
Re: Split string on a specific length -
Vince - 05.03.2012
https://sampwiki.blast.hk/wiki/Strmid ?
Re: Split string on a specific length - T0pAz - 05.03.2012
Quote:
Originally Posted by Vince
|
How to put the splitted string into arrays dynamically?
Re: Split string on a specific length -
R0FLC0PTER - 05.03.2012
What do you mean with dynamically?
Here's the example you gave, but written with strmid
pawn Код:
new sampletext[64] = "This is a sample text which will be splited into arrays";
new arrayofstr[2][128];
strmid(arrayofstr[0], sampletext, 0, 27); // Copy character range 0 - 27
strmid(arrayofstr[1], sampletext, 28, strlen(sampletext) - 1); // Copy character range 28 - end of string
printf("%s", arrayofstr[0]); // which will print out "This is a sample text which"
I haven't tested it, but the code should work.
Re: Split string on a specific length - T0pAz - 05.03.2012
Quote:
Originally Posted by R0FLC0PTER
What do you mean with dynamically?
Here's the example you gave, written with strmid
pawn Код:
new sampletext[64] = "This is a sample text which will be splited into arrays"; new arrayofstr[2][128]; strmid(arrayofstr[0], sampletext, 0, 27); // Copy character range 0 - 27 strmid(arrayofstr[1], sampletext, 28, strlen(sampletext) - 1); // Copy character range 28 - end of string printf("%s", arrayofstr[0]); // which will print out "This is a sample text which"
I haven't tested it, but the code should work.
|
I think I will make a custom function for it. Thanks!