Author Topic: Removing all tags  (Read 885 times)

Well, I'm working on a script
and it relies on removing all <> tags.
Though I don't know how to do this.
Help?


function findNextTag(%string)
{
   %start = strPos(%string,"<");
   %end = strPos(%string,">");
   return %start SPC %end;
}
function removeTags(%string)
{
   while(findNextTag(%string) !$= "")
   {
      %tagpos = findNextTag(%string);
      %start = getWord(%tagpos,0);
      %end = getWord(%tagpos,1);
      %sut = getSubStr(%string,0,%start);
      %eut = getSubStr(%string,%end,strLen(%string));
      %newstr = %sut @ %eut;
   }
   return %newstr;
}

this makes me crash
anyone help?

Why don't you just load the whole script or whatever as a variable, then do strReplace(%script, "<", "");strReplace(%script, ">", "");?

Why don't you just load the whole script or whatever as a variable, then do strReplace(%script, "<", "");strReplace(%script, ">", "");?
I have to remove the entire tag
including the things inside.

Oh.
Aren't there wildcards in torque?

is it absolutely neccesary to do this ingame? I know how to do it with Notepad++...


1 Aren't there wildcards in torque?

2 is it absolutely neccesary to do this ingame?
1 whats that

2 if it wasn't then I wouldn't have posted.

i think i got it
Code: [Select]
function findNextTag(%string)
{
   %start = strPos(%string,"<");
   %end = strPos(%string,">");
   return %start SPC %end;
}
function removeTags(%string)
{
   while(findNextTag(%string) !$= "-1 -1")
   {
      %tagpos = findNextTag(%string);
      %start = getWord(%tagpos,0);
      %end = getWord(%tagpos,1);
      %sut = getSubStr(%string,0,%start);
      %eut = getSubStr(%string,%end,strLen(%string) - 1);
      %newstr = %sut @ %eut;
   }
   return %newstr;
}
i was testing the first function
echo(findNextTag("hi<bluh>quack")); returned 2 7
echo(findNextTag("blub")); returned -1 -1

and i think the substring has to be a valid position in the string, maybe not

and i think the substring has to be a valid position in the string, maybe not
getSubStr(string,start,end) - Used to get a section of a string. Start and End are integers.

EDIT: Crashed me.
« Last Edit: March 02, 2012, 06:51:31 PM by Brian Smithers »

um, just tested it
i think i crashed... not sure though haha
and i know they're integers, but does it have to be a valid position in the string?
ie

duckquack
012345678

would subString("duckquack", 0, 10); return duckquack or an error?

edit: closed it due to being frozen...
and fuuu, now i gotta retype it all

edit: oh, duh
we're not updating the stuff in the while loop

edit again:
test this?
Code: [Select]
function findNextTag(%string)
{
   %start = strPos(%string,"<");
   %end = strPos(%string,">");
   return %start SPC %end;
}
function removeTags(%string)
{
   %newstr = %string;
   while(findNextTag(%newstr) !$= "-1 -1")
   {
      %tagpos = findNextTag(%string);
      %start = getWord(%tagpos,0);
      %end = getWord(%tagpos,1);
      %sut = getSubStr(%string,0,%start);
      %eut = getSubStr(%string,%end,strLen(%string) - 1);
      %newstr = %sut @ %eut;
   }
   return %newstr;
}
« Last Edit: March 02, 2012, 06:57:26 PM by phflack »

Shouldn't
Code: [Select]
   %newstr = %string;Go inside the while() statement?

getSubStr(string,start,end) - Used to get a section of a string. Start and End are integers.

EDIT: Crashed me.
Nope.

getSubStr(string,start,length)

Shouldn't
Code: [Select]
   %newstr = %string;Go inside the while() statement?
no, then it'd reset each time
Nope.

getSubStr(string,start,length)
so then...
Code: [Select]
function findNextTag(%string)
{
   %start = strPos(%string,"<");
   %end = strPos(%string,">");
   return %start SPC %end;
}
function removeTags(%string)
{
   %newstr = %string;
   while(findNextTag(%newstr) !$= "-1 -1")
   {
      %tagpos = findNextTag(%string);
      %start = getWord(%tagpos,0);
      %end = getWord(%tagpos,1);
      %sut = getSubStr(%string,0,%start);
      %eut = getSubStr(%string,%end,strLen(%string) - 1 - %end);
      %newstr = %sut @ %eut;
   }
   return %newstr;
}

no, then it'd reset each timeso then...
Code: [Select]
function findNextTag(%string)
{
   %start = strPos(%string,"<");
   %end = strPos(%string,">");
   return %start SPC %end;
}
function removeTags(%string)
{
   %newstr = %string;
   while(findNextTag(%newstr) !$= "-1 -1")
   {
      %tagpos = findNextTag(%string);
      %start = getWord(%tagpos,0);
      %end = getWord(%tagpos,1);
      %sut = getSubStr(%string,0,%start);
      %eut = getSubStr(%string,%end,strLen(%string) - 1 - %end);
      %newstr = %sut @ %eut;
   }
   return %newstr;
}
did you test this?

stripColorCodes( stringtoStrip )
stripMLControlChars( sourceString )


do those not work

stripColorCodes( stringtoStrip )
stripMLControlChars( sourceString )


do those not work
Do those take out every single tag.