Author Topic: Get striPos to move to the next instance of a string?  (Read 432 times)

Code: [Select]
function sanitizeFontTags(%string) {
while(stripos(%string, "<font:") != -1) {
%start = stripos(%string, "<font:");
%end = stripos(%string, ">");

%toRemove = getSubStr(%string, %start, %end - %start);

%string = strReplace(%string, %toRemove, "");
}

return %string;
}

getSubStr(...): error, starting position and desired length must be >= 0: ([source string],9, -3)

SMF doesn't show a couple of characters in the source string:

I know stripMLControlChars exists, but it also strips out color tags. I just want font tags stripped.
If I can get striPos to move to the next instance of ">" (until %end is greater than %start), this should work fine. I just don't know how I should approach it.

you could use striPos's offset parameter: striPos(%srcString, %searchString, %offset)

you'd just set %start as the offset if you wanted to guarantee that it would find something after that index

so %offset will ignore anything before that index in the string?


Code: [Select]
function stripFont(%str)
{
while((%pos = (striPos(%str, "<font:"))) >= 0)
{
%text = getSubStr(%str, %pos, striPos(%str, ">", %pos) - %pos + 1);
%str = strReplace(%str, %text, "");
}

return %str;
}

Just tried this, seems to work: messageBoxOK("", stripFont("<font:impact:20>asdf<br><font:impact:20>ggg"));

have you tried it with something like "<font:sdasdsa:20><color:2a4022><font:ghaggas:10>BenbEnen<font:feaf:6>"

%text = getSubStr(%str, %pos, striPos(%str, ">", %font) - %pos + 1);

i think %font should be %pos here right? otherwise it's just a compressed version of what he would have

Works fine to me:


2nd try using real stuff:

messageBoxOK("", stripFont("<font:impact:20:20><color:2a4022><font:arial:10>BenbEnen<font:impact:6>a"));

%text = getSubStr(%str, %pos, striPos(%str, ">", %font) - %pos + 1);
I figured there was a typo in the code when I made it, you had my original post before I edited it lol

wasn't expecting that much lol
Code: [Select]
function sanitizeFontTags(%string) {
//getSubStr(...): error, starting position and desired length must be >= 0: ("209 >[<font:Impact:20>MOD>]<font:Palatino linotype:24> <color:007EFF>The Original Bob <color:ffffff>: WOW",9, -3)
while(stripos(%string, "<font:") != -1) {
%start = stripos(%string, "<font:");
%end = stripos(%string, ">", %start)+1;

%toRemove = getSubStr(%string, %start, %end - %start);

%string = strReplace(%string, %toRemove, "");
}

return %string;
}
works, thanks guys