generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: manipulating strings

Previous Thread :: Next Thread 
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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
Mathfreak231 is not online. Mathfreak231
Joined: 21 Jun 2010
Total Posts: 5311
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 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:05 AM
thanks i found it :)
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:14 AM
thanks alot :)
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 11:15 AM
Yw :D
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:16 AM
its not working :/
Report Abuse
Dr01d3k4 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 11:25 AM
What are lines 12 and 14?
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:27 AM
line12: string:gsub(tostring(a - 1), letterTable[a])

line 14: coded.Value = stringval
Report Abuse
rayoma is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
29 Jul 2012 11:29 AM
@Rayoma: Oh yeah, oops :3
Report Abuse
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:29 AM
i have and im still having the same problem
Report Abuse
Dr01d3k4 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
29 Jul 2012 11:50 AM
any ideas why :/
Report Abuse
Dr01d3k4 is not online. 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
carbondudeoxide is not online. carbondudeoxide
Joined: 04 Mar 2011
Total Posts: 556
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image