How do I replace a $ in a Lua string?
Asked Answered
O

1

7

How do you replace a dollar sign in Lua since it is a special character in pattern matching?

I've tried this:

string.gsub("$44,000.00", "$", "")
> "$44,000.00"

But all it does is add a blank at the end of the string. For example

string.gsub("$44,000.00", "$", "what")
> "$44,000.00what"
Ornis answered 16/6, 2014 at 13:51 Comment(0)
A
9

Knowing $ is a special character is half way to the answer. Use % to escape magic characters:

string.gsub("$44,000.00", "%$", "what")
Anciently answered 16/6, 2014 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.