Can't Use Downloaded HTML Data as a String

I have my script download some HTML data, store it in a variable, and split it into segments. However, it seems as if Defold doesn’t treat the data as a string, so I can’t do things like use DefString’s “split” function. I’ve tried concatenating the data with a regular string variable, but it still doesn’t work. If you need an example program, I could put one together.

Could you upload an example project zip of what you are currently trying to do? This is the source of defstring’s split, I’m not sure if it could cause a problem with the HTML data. https://github.com/subsoap/defstring/blob/master/defstring/defstring.lua

function M.split(s,delimiter)
	delimiter = delimiter or '%s'
	local t={}
	local i=1
	for str in string.gmatch(s, '([^'..delimiter..']+)') do
		t[i] = str
		i = i + 1
	end
	return t
end

After some more investigation, I think the problem could be some of of the characters I use in defstring.replace. Since it seems like I can’t use defstring.split(my_string, "Long string", "@") without it replacing every character in “Long string”, I do this instead:

local data = defstring.replace(html_data, "<li class=\"project-list-item\">", "@")
local my_table = defstring.split(data, "@")

I’ve got an example project on the way, but it might take a bit.

18 hours counts a “a bit”, right? Anyways, here’s the example project. It has an interchangeable “replace.script”, which has the code from my previous post, and “no_replace.script”, which is mostly the same code, but without the defstring.replace() part.

EDIT: defstring.contains() returns true, so it’s just .replace() that’s acting up.

1 Like