ID:2778030
 
(See the best response by Kozuma3.)
mob/verb/Guild_Options()
set category = "Commands"
set hidden = 1
if(usr.guildin == 0)
switch(alert("You are not in a guild. Would you like to create one?","Guild Options","Yes","No"))
if("Yes")
var/guild = input("Name it (font color allowed but it cant be really big keep it to medium)","") as text
var/name = html_encode(guild)
if(length(name) > 26)
usr<<"Your guild has to be less than 26 characters"
return
else


Problem description: Basically im trying to let people create a guild using HTML but once they set the HTML tag I want to parse it and see if the final length is > 26.

EG: I enter in "Test"
-- should check if "Test" is > 26 while ignoring all the font color = stuff I had to put in front of each letter

Best response
proc/SizeOfStringWithoutHTML(string)
var a,b,list/l = splittext(string,"")
for()
a = l.Find("<")
b = l.Find(">",a)
if(!a||!b){break}
l.Cut(a,b+1)
return l.len


world << SizeOfStringWithoutHTML("<font color=#F00>Hello!</font>")


The above code will output 6 since "Hello!"
In response to Kozuma3
Kozuma3 wrote:
proc/SizeOfStringWithoutHTML(string)
> var a,b,list/l = splittext(string,"")
> for()
> a = l.Find("<")
> b = l.Find(">",a)
> if(!a||!b){break}
> l.Cut(a,b+1)
> return l.len

world << SizeOfStringWithoutHTML("<font color=#F00>Hello!</font>")

The above code will output 6 since "Hello!"


Interesting. I was trying to avoid getting into the whole process of chopping html out and isolating letters because I thought html encode took care of it.

Only question I have is the for loop, there is no condition specified is it meant to be like that?

Edit: Tested it and it works fine. Thanks a lot!
for() will continue on forever until you hit a return or break.

First you split the text into single characters via splittext()

Next you start the infinite loop and check for the position of < and the > after it.

If one or the other isn't found, it breaks out of the infinite loop and returns the length of l, which is the list that contains all the characters seperated via splittext()

If both are found, it will remove those characters and all that's between them from the list.

Once neither is found and all has been removed, it return's l's length which is the character count.
In response to Kozuma3
Kozuma3 wrote:
for() will continue on forever until you hit a return or break.

First you split the text into single characters via splittext()

Next you start the infinite loop and check for the position of < and the > after it.

If one or the other isn't found, it breaks out of the infinite loop and returns the length of l, which is the list that contains all the characters seperated via splittext()

If both are found, it will remove those characters and all that's between them from the list.

Once neither is found and all has been removed, it return's l's length which is the character count.

ya I should have realized why you had an inf loop once I saw the break. I guess I was too worried with the "omg an inf loop what?" haha
In response to Naruto 5292
Naruto 5292 wrote:
Interesting. I was trying to avoid getting into the whole process of chopping html out and isolating letters because I thought html encode took care of it.

Just real quick, that's not what html_encode does. It takes text and returns a string with all html tags within that text escaped. Well, with the exception of the very old style like \red, which is removed entirely.
In response to Spevacus
So its basically the inverse of what I wanted. Funny thing is I checked the DM guide and misunderstood it lol
In response to Naruto 5292
Ha! Everyone's been there, no worries :)