[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: String manipulation
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sun, 2 Nov 2014 07:22:25 +0200
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