[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Replacements of String Characters in LUA by using the Character Indexes
- From: "Vadim A. Misbakh-Soloviov" <lua-l@...>
- Date: Sat, 11 Mar 2017 13:26:16 +0700
> in LUA Programming
> write a LUA program
> standard LUA Function
> Please do not write it as "LUA", which is both ugly and confusing, because
then it becomes an acronym with different meanings for different people. So,
please, write "Lua" right!
> But I am not able to find any standard LUA Function to replace the
> characters of the string by using character indexes.
It isn't one.
Lua is not a Python and unlike Python, which trying to provide you as much as
possible, Lua tries to provide you as less, as possible. It is a key feature
So, it is no function to replace by indexes, but you still can write you own
with few ways:
1) playing with `str:match()`, `str:find()` and so on
2) playing with `str:match()` (to comapre), `str:sub()` (to split between
indexes), and so on
3) playing with `str:gsub()`. It accepts custom function as "replace"
It captures the pattern from "pattern" parameter and passes it to the function
In that function you can do anything you want with received substring. And
then you can return the result, and it will be returned by gsub then.
> Please provide me with any reference guide or any standard lua function to
> replace the strings in lua.
1) http://lua-users.org/wiki/StringLibraryTutorial (^F -> gsub)
2) https://www.lua.org/pil/20.html (to 20.4)
3) https://www.lua.org/manual/5.0/manual.html#5.3 (^F -> gsub)