Lua How to replace 1 specific character inside table without whole string? -
How to show a specific character already.
table {"abc"} return string. All (table [1], 2, 2) b but change the entire string Without a table, you want to change 1 specific character.
from table = {"abc"}
table = {"axc"}
In Lua, the string is strictly irreversible, so they not changed You can. <. / P>
In this way, the only way to complete this is to create a new string with the content and insert it in the table [1] . Whether it is inside the string table or not, it does not matter.
This will be done, for example, by beginning and ending the string and adding them to the new part:
local index = 2 - the character that we Table [1] = string. Sub (table [1], 1, index-1). "X" .. string.sub (table [1], index + 1, -1) This will remove all the characters from the beginning of the string, as long as we want to "substitute", before adding the new character, then the rest of the string Join C in which we do not include the "replace".
However, in most cases, it is not very advisable to play with such a letter, because Lua is quite powerful Pattern matching and replacement features, such that you can easily and Also allows to change complex substrings. (Examples available from programming in Lea)
Comments
Post a Comment