SA-MP Forums Archive
Find and remove bits of string between { and } - 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: Find and remove bits of string between { and } (/showthread.php?tid=661895)



Find and remove bits of string between { and } - [DK]Dark_Knight - 18.12.2018

Hey all,

I'm looking for the best way to remove any text in between a { and }, assuming they both exist.
For example
Код:
STRING: {FFFFFF}My String {00FF00}Here
RETURNS: My String Here

AND

STRING: {FFFFFF} My String { Here
Returns: My String { Here
I'm currently using this:
Код:
                        // REMOVE ANY COLOR CODES!!
			new bool:open = false;
			for(new j=0; j<32; j++)
			{
				if(inputtext[j] == '{') open = true;
				if(open == false)
				{
					format(str, sizeof(str), "%s%c", str, inputtext[j]);
				}

				if(inputtext[j] == '}') open = false;
			}
which does the job, but if a player enters a { without closing it, everything after will be ignored.
NOTE: this is just a quick snippit i whipped up.
I was looking as sscanf, but unsure on how to do it. Gave it a good crack tho

Cheers


Re: Find and remove bits of string between { and } - Threshold - 18.12.2018

Is it color codes only that you're trying to remove? Or any string between braces?


Re: Find and remove bits of string between { and } - [DK]Dark_Knight - 18.12.2018

Oh awesome. Didn't even think to search for a regex plugin.
Gosh it's an oldy too haha.

I'll do some experimenting later with the
Код:
{ one { two three }
Cheers *****!! Also when did you get back? I recall you left samp few years back? Around when I left it. Haha