|
| 29 Jul 2012 10:54 AM |
hi is there a way of replacing specific characters in a string with a different character/s?
ie string1 = "string"
replace 'g' with 'gy'
and string1 = "stringy" ??
|
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 10:56 AM |
wiki.roblox.com
search "String Manipulation"
there's something on that somewhere
~This sig is false~ |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 29 Jul 2012 10:57 AM |
local string1 = "string"; print(string1);
string1:gsub("g", "gy"); print(string1);
http://wiki.roblox.com/index.php/Function_Dump/String_Manipulation |
|
|
| Report Abuse |
|
|
| |
|
|
| 29 Jul 2012 11:10 AM |
ok with that knowledge is there a better more efficiant way of doing this or somethign similar?
local step1 = string.gsub(initial.Value, "1", "A") local step2 = string.gsub(step1, "2", "B") local step3 = string.gsub(step2, "3", "C") local step4 = string.gsub(step3, "4", "D") local step5 = string.gsub(step4, "5", "E") local step6 = string.gsub(step5, "6", "F") local step7 = string.gsub(step6, "7", "G") local step8 = string.gsub(step7, "8", "H") local step9 = string.gsub(step8, "9", "I") local step0 = string.gsub(step9, "0", "J") coded.Value = step0 |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 29 Jul 2012 11:12 AM |
local letterTable = {"J", "A", "B", "C", "D", "E", "F", "G", "H", "I"}; local string = inital.Value; for a = 1, #letterTable do string:gsub(tostring(a - 1), letterTable[a]); end coded.Value = string; |
|
|
| Report Abuse |
|
|
| |
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
| |
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 29 Jul 2012 11:18 AM |
| O.o that's odd. Unless it's a thing with lua array indexes beginning at 1, I can't see anything wrong o.O |
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:20 AM |
i cant see anything wrong either, this is what the oputput is saying:
17:20:07 - Workspace.Strings!.Script:12: attempt to index local 'string' (a number value) 17:20:07 - Script "Workspace.Strings!.Script", Line 12 17:20:07 - stack end 17:20:07 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
rayoma
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1911 |
|
|
| 29 Jul 2012 11:22 AM |
| You overwrote the string table. Rename the variable `local string = inital.Value;` to something else. |
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:22 AM |
i just tried this: local string = tostring(initial.Value) for a = 1, #letterTable do string:gsub(tostring(a - 1), letterTable[a]) end coded.Value = stringval
and this is now the error: local string = tostring(initial.Value) for a = 1, #letterTable do string:gsub(tostring(a - 1), letterTable[a]) end coded.Value = stringval |
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:22 AM |
sorry: 17:21:03 - String expected 17:21:03 - Script "Workspace.Strings!.Script", Line 14 17:21:03 - stack end 17:21:03 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
|
| 29 Jul 2012 11:27 AM |
line12: string:gsub(tostring(a - 1), letterTable[a])
line 14: coded.Value = stringval |
|
|
| Report Abuse |
|
|
rayoma
|
  |
| Joined: 13 Nov 2009 |
| Total Posts: 1911 |
|
|
| 29 Jul 2012 11:28 AM |
Like I said
> You overwrote the string table. Rename the variable local string = inital.Value; to something else.
|
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:29 AM |
just realised line 14 was coded.Value = stringval not coded.Value = string
unfortunatly i just tried it and it had no errors ^.^ but it did not encode :/ |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
| |
|
|
| 29 Jul 2012 11:29 AM |
| i have and im still having the same problem |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 29 Jul 2012 11:31 AM |
Use this instead of the code up there ^
local letterTable = {"J", "A", "B", "C", "D", "E", "F", "G", "H", "I"}; local encodingString = inital.Value; for a = 1, #letterTable do encodingString:gsub(tostring(a - 1), letterTable[a]); end coded.Value = encodingString; |
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:33 AM |
| no errors but when i put "1234567" into the initial value the code3d value is also "1234567" when it should be "ABCDEFG" |
|
|
| Report Abuse |
|
|
| |
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 29 Jul 2012 11:52 AM |
Extremely ugly hack, but it works, somehow...
local encodingString = tostring(initial.Value); local letterTable = {"J", "A", "B", "C", "D", "E", "F", "G", "H", "I"};
function replace(stringToReplace, replaceChar, replaceWith) local replacedString = stringToReplace; for letter = 1, #stringToReplace, 1 do if (tostring(stringToReplace:sub(letter, letter)):lower() == tostring(replaceChar):lower()) then replacedString = replace(stringToReplace:sub(1, letter - 1)..replaceWith..stringToReplace:sub(letter + 1), replaceChar, replaceWith); break; end end return replacedString; end
for checkLetter = 1, #letterTable, 1 do local replaceChar = (checkLetter - 1); local replaceWith = letterTable[checkLetter]; encodingString = replace(encodingString, replaceChar, replaceWith); end
coded.Value = tostring(encodingString); |
|
|
| Report Abuse |
|
|
|
| 29 Jul 2012 11:56 AM |
| by the looks of that its probably better to go with my original nooby one? it looks more efficiant :D |
|
|
| Report Abuse |
|
|