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)
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.
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.
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.
Try:
name = "^aH^ai" name = name:gsub("%^a", "")
See also: http://lua-users.org/wiki/StringLibraryTutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With