How to cut a piece of text? - 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: How to cut a piece of text? (
/showthread.php?tid=478364)
How to cut a piece of text? -
LastChaos - 29.11.2013
How to cut the first 8 characters?
Re: How to cut a piece of text? -
xVIP3Rx - 29.11.2013
What do you mean ? You want to delete "{00ff00}" ?
Can you explain more ?
Re: How to cut a piece of text? -
ikbenremco - 29.11.2013
Use strmid.
https://sampwiki.blast.hk/wiki/Strmid
strmid(string, "ItWillCopeThis notthis", 1, 14); //string contains "ItWillCopeThis"
1 stands for the first character and 14 for the last.
Re: How to cut a piece of text? -
xVIP3Rx - 29.11.2013
Quote:
Originally Posted by ikbenremco
Use strmid.
https://sampwiki.blast.hk/wiki/Strmid
strmid(string, "ItWillCopeThis notthis", 1, 14); //string contains "ItWillCopeThis"
1 stands for the first character and 14 for the last.
|
In that case
Strdel will be better
pawn Код:
new string[42] = "We will delete everything apart from this";
strdel(string, 0, 37); // string is now "this"
Re: How to cut a piece of text? -
Konstantinos - 29.11.2013
If you don't know the position of that piece of text and you want to remove the first hex color {RRGGBB}:
pawn Код:
stock RemoveHexColors( sz_Text[ ] )
{
new
iStart = strfind( sz_Text, "{" ),
iEnd = strfind( sz_Text, "}" ),
bool: using_color = true
;
if( iStart != -1 && iEnd != -1 && iEnd - iStart == 7 )
{
for( new i = iStart + 1; i != iEnd; i++ )
{
if( ( sz_Text[ i ] < 'A' || sz_Text[ i ] > 'Z' ) && ( sz_Text[ i ] < 'a' || sz_Text[ i ] > 'z' ) && ( sz_Text[ i ] < '0' || sz_Text[ i ] > '9' ) )
{
using_color = false;
break;
}
}
if( using_color )
{
strdel( sz_Text, iStart, iEnd + 1 );
return 1;
}
}
return 0;
}
I know it can be written in a better way.
And if you want to remove all the hex colors:
pawn Код:
new
string[ 64 ] = "Some test with colors {00FF00}and {FFFFFF}another color!"
;
while( RemoveHexColors( string ) ) RemoveHexColors( string );
RemoveHexColors will be called as many as hex color exists + 1.
Re: How to cut a piece of text? -
LastChaos - 29.11.2013
Big thanks guys