[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Simple Question
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Thu, 2 Oct 2008 18:31:25 +0200
2008/10/2 Xruptor <derkyle@gmail.com>:
> Question: What is a good way to remove all Magic Characters from a string
> without distorting or breaking the accuracy of the original string? I
> figure it has to do with the (%W) pattern. However all my attempts usually
> break the string somehow or distort it. My goal is to remove all possible
> magic characters from a string before parsing it in a string.find or any
> other string function.
>
> I'm trying to parse chat information but people are bypassing the
> string.find function by adding special magic characters to their text
> strings. Sometimes it breaks the string and sometimes the parse bypasses
> all find functions.
>
> This is why I would like to strip all magic characters from a string before
> parsing ;) Help is always appreciated.
If you want to keep the original string unchanged, what you want is
not stripping special characters, but escaping them. To do that you
can use the following function:
function escape(str)
return (str:gsub("%W", "%%%1"))
end