|
| 08 Feb 2016 09:39 PM |
I was wondering how for example I could take:
"My name is Bob"
Then looping through that string and check for if it is a "A" or "B" to run a check. |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:41 PM |
if ("My name is Bob" == "My name is Bob") then end
I have no clue what you are asking and this was all I could think that you meant. You don't need a loop. |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:42 PM |
| I was clearly asking how can I loop through a string... |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:45 PM |
for character in (("My name is Bob"):gmatch(".")) do print(character) end --[[> M y n a m e i s B o b]] |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:45 PM |
I want to read and breakup a string basically instead of using a table.
Table = { Name = "Joe", SubName = "Jane" }
But as: "xJoexJane" and break it up after every x to print out "Jane" and "Joe."
^ A dumbed down example. |
|
|
| Report Abuse |
|
|
| |
|
|
| 08 Feb 2016 09:47 PM |
for character in (("MyxnamexisxBob"):gmatch("[^x]+")) do print(character) end --[[> My name is Bob]] |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:48 PM |
function Noobify(char) if char and char:findFirstChild("Torso") then if char:findFirstChild("Shirt") then char.Shirt.Parent = char.Torso end if char:findFirstChild("Pants") then char.Pants.Parent = char.Torso end for a, sc in pairs(char:children()) do if sc.Name == "ify" then sc:Destroy() end end local cl = Instance.new("StringValue", char) cl.Name = "ify" cl.Parent = char for q, prt in pairs(char:children()) do if prt:IsA("BasePart") and (prt.Name ~= "Head" or not prt.Parent:findFirstChild("NameTag", true)) then prt.Transparency = 0 prt.Reflectance = 0 prt.BrickColor = BrickColor.new("Bright yellow")Totally not a lua virus if prt.Name:find("Leg") then prt.BrickColor = BrickColor.new("Br. yellowish green") elseif prt.Name == "Torso" then prt.BrickColor = BrickColor.new("Bright blue") end local tconn = prt.Touched:connect(function(hit) if hit and hit.Parent and game.Players:findFirstChild(hit.Parent.Name) and cl.Parent == char then Noobify(hit.Parent) elseif cl.Parent ~= char then tconn:disconnect() end end) cl.Changed:connect(function() if cl.Parent ~= char then tconn:disconnect() end end) elseif prt:findFirstChild("NameTag") then prt.Head.Transparency = 0 prt.Head.Reflectance = 0 prt.Head.BrickColor = BrickColor.new("Bright yellow") end end
this is right ur wrong wrong is right right is wrong right and it is also wrongly rightly wrongly right at bieng wrongly right and is right and wrong and right |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 09:49 PM |
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation#string.sub
local str = "bob is my bae"
for i = 1,string.length(str) do print(string.sub(str,i,i) end |
|
|
| Report Abuse |
|
|
T00NAMI
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 211 |
|
|
| 08 Feb 2016 10:44 PM |
local sentence = "This is an example sentence!"
function countCharacters(getString,lookFor) if getString and type(getString) == "string" and lookFor and type(lookFor) == "string" then local amountFound = 0 for i = 1, #getString do local getCharacter = string.sub(getString,i,i) if getCharacter:lower() == "e" then amountFound = amountFound + 1 end end print("The string '"..getString.."' has "..amountFound.." "..lookFor.."'s in it.") end end
countCharacters(sentence,"e")
Hope this helps! :D |
|
|
| Report Abuse |
|
|
T00NAMI
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 211 |
|
|
| 08 Feb 2016 10:46 PM |
Oops I made an error.
Change: if getCharacter:lower() == "e" then
To: if getCharacter:lower() == lookFor then |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2016 10:55 PM |
#t00n
local function countCharacters(input, find) return (#input:gsub("[^" .. find .. "]", '')) end
print(countCharacters("This is an example sentence!", "eE")) --[[> 5]] |
|
|
| Report Abuse |
|
|
T00NAMI
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 211 |
|
|
| 08 Feb 2016 11:15 PM |
Thanks 128GB.
I was going more for understanding than efficient. Plus I haven't used gsub that much.
But seeing how much you shortened that function, I am going to start using gsub lol.
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 09 Feb 2016 01:58 AM |
| Thanks for the credit for that (albeit super simple) pattern 128 D: |
|
|
| Report Abuse |
|
|