EcIiptic
|
  |
| Joined: 12 Aug 2009 |
| Total Posts: 13737 |
|
|
| 20 May 2014 04:41 PM |
I think string:sub() is read only so...
How would I do this:
String = "Hello"
String:sub(2,2) = "a"
How would I go about setting the individual character to a new one?
#Piano |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 20 May 2014 04:44 PM |
text = 'daaamn' for i = 1, text:len() do --wait() print(text:sub(i,i)) end |
|
|
| Report Abuse |
|
|
EcIiptic
|
  |
| Joined: 12 Aug 2009 |
| Total Posts: 13737 |
|
|
| 20 May 2014 04:45 PM |
wat
thats not at all what I asked.
im asking how to set a selected character in a string.
like
String = "Hello"
String:sub(2,2) = "a"
--String now equals "Hallo"
#Piano |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 21 May 2014 08:43 AM |
txt = 'Hello'
for v in txt:gmatch('e') do new = txt:gsub('e', 'a') print(new) end |
|
|
| Report Abuse |
|
|
ajmhm1111
|
  |
| Joined: 22 Jun 2013 |
| Total Posts: 164 |
|
|
| 21 May 2014 10:13 AM |
Hello,
function overrideString(stringToOverride,p1,p2,stringToPlace) return stringToOverride:sub(1,p1 - 1)..stringToPlace..stringToPlace:sub(p2 + 1,#stringToPlace) end
print(overrideString("Hello",3,4,"ee")) -->prints Heeeo
Hope this helps
--ajmhm1111
|
|
|
| Report Abuse |
|
|
ajmhm1111
|
  |
| Joined: 22 Jun 2013 |
| Total Posts: 164 |
|
|
| 21 May 2014 10:15 AM |
Aah oops
function overrideString(stringToOverride,p1,p2,stringToPlace) return stringToOverride:sub(1,p1 - 1)..stringToPlace..stringToOverride:sub(p2 + 1,#stringToOverride) end
print(overrideString("Hello",3,4,"el")) -->prints Heelo
Sorry about that
--ajmhm1111 |
|
|
| Report Abuse |
|
|