Find and remove bits of string between { and }
#1

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)