Lua String replace

Frank picture Frank · Nov 28, 2010 · Viewed 95.4k times · Source

How would i do this?

I got this:

name = "^aH^ai"
string.gsub(name, "^a", "")

which should return "Hi", but it grabs the caret character as a pattern character

What would be a work around for this? (must be done in gsub)

Answer

Kknd picture Kknd · Nov 28, 2010

Try:

name = "^aH^ai"
name = name:gsub("%^a", "")

See also: http://lua-users.org/wiki/StringLibraryTutorial