lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dirk,

Thanks..so much. From my understanding '[[]]' just stringize its content. What about a case where I would want to stringize the returned value of a function. And [[]] is a syntax sugar of what?

Emeka

On Nov 2, 2014 6:22 AM, "Dirk Laurie" <dirk.laurie@gmail.com> wrote:
2014-10-31 19:33 GMT+02:00 Emeka <emekamicro@gmail.com>:

> mystring = "google+facebook"
...
> if mystring.sub(i,i) == ' " '  then .... end It is not comparing at all ,and
> this also failed.

Well, mystring does not contain a double-quote at all: those
double-quotes are the string delimiters.

So for a start you need something like:

mystring = [["google+facebook"]]

In general, the moment I need to put any string searches
inside a for loop I know I have missed a trick.

For example: find whether mystring contains a substring
between two double-quotes.

Method 1

local p,q
for i = 1,#mystring do if mystring:sub(i,i)=='"' then
   if not p then p=i
   elseif not q then q=i; break
   end
end end
if q then -- substring found
end

Method 2:

p, q = mystring:find[[%b""]]
if q then -- substring found
end