Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua String replace

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)

like image 263
Frank Avatar asked Nov 28 '10 16:11

Frank


People also ask

How do I replace text in a string?

The Java string replace() method will replace a character or substring with another character or string. The syntax for the replace() method is string_name. replace(old_string, new_string) with old_string being the substring you'd like to replace and new_string being the substring that will take its place.

What is GSUB in Lua?

gsub() function has three arguments, the first is the subject string, in which we are trying to replace a substring to another substring, the second argument is the pattern that we want to replace in the given string, and the third argument is the string from which we want to replace the pattern.

What is string sub Lua?

LuaServer Side ProgrammingProgramming. Another important function of the Lua's string library is the string. sub() function. The string. sub() function is used to extract a piece of the string.


1 Answers

Try:

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

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

like image 172
Kknd Avatar answered Oct 04 '22 06:10

Kknd