maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 31 Mar 2015 04:20 PM |
value = "-1^(1/2)" value:gsub ("-1^(1/2)","i") print (value) --> -1^(1/2)
Why doesn't it substitute that for i? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 31 Mar 2015 04:25 PM |
| Because you have to define the gsub, not just the value variable. |
|
|
| Report Abuse |
|
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 31 Mar 2015 04:29 PM |
What? Isn't that a valid shortcut for string functions? |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 31 Mar 2015 04:31 PM |
You need to escape parentheses with the percent character, and string:gsub() doesn't modify the string, because Lua strings are immutable. It returns a new string. So you need to do value = value:gsub(...)
value = "-1^(1/2)" value = value:gsub("-1^%(1/2%)", "i") print(value) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 31 Mar 2015 07:25 PM |
| That makes sense, but why do I have to escape for parenthesis if the string is in quotes? |
|
|
| Report Abuse |
|
|