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 » Scripters
Home Search
 

Re: Loop through a String - Help

Previous Thread :: Next Thread 
xSpectrumWolfx is not online. xSpectrumWolfx
Joined: 30 Nov 2011
Total Posts: 2858
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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
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
xSpectrumWolfx is not online. xSpectrumWolfx
Joined: 30 Nov 2011
Total Posts: 2858
08 Feb 2016 09:42 PM
I was clearly asking how can I loop through a string...
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
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
xSpectrumWolfx is not online. xSpectrumWolfx
Joined: 30 Nov 2011
Total Posts: 2858
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
xSpectrumWolfx is not online. xSpectrumWolfx
Joined: 30 Nov 2011
Total Posts: 2858
08 Feb 2016 09:46 PM
Thanks both of you.
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
08 Feb 2016 09:47 PM
for character in (("MyxnamexisxBob"):gmatch("[^x]+")) do
print(character)
end --[[> My
name
is
Bob]]
Report Abuse
ranvir2050 is not online. ranvir2050
Joined: 20 Dec 2014
Total Posts: 321
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
Ripepperoni is not online. Ripepperoni
Joined: 04 Jul 2010
Total Posts: 5715
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 is not online. 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 is not online. 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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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