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: String Questions..

Previous Thread :: Next Thread 
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
28 Jun 2014 11:54 PM
I have 2 questions about strings.

1 How can i make a check to make sure a string has a certain number of numbers/letters/symbols in it?

2 how can i make a check to make sure a string has numbers in it?

I really need this, i dont even know if this is possible or not.
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
28 Jun 2014 11:57 PM
1) string.len(STRING) or #"STRING"

2)if tonumber(STRING) then end

Report Abuse
Wehttam664 is not online. Wehttam664
Joined: 02 Oct 2009
Total Posts: 767
28 Jun 2014 11:59 PM
Lua has a system of string patterns that can be used to accomplish this task. Search up 'Lua regex' and the first result on patterns should be a viable answer. I would post the link, but apparently posting the link to the Lua wiki is not allowed.
Report Abuse
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
29 Jun 2014 12:10 AM
Thanks i looked into it and it looks way out of my range of Lua coding, could you assist me with a simple code of my first questions, it would be much apprecieated :)
Report Abuse
Wehttam664 is not online. Wehttam664
Joined: 02 Oct 2009
Total Posts: 767
29 Jun 2014 12:14 AM
As for getting the string's character length, @SenseiWarrior's method is viable, but the number check @SenseiWarrior provided will not work, as any letter will cause a return of 0.

if (string.match("yourstring11", '%d')~=nil) then
-- CODE
end

That should check for a number anywhere in the string, as %d finds a number, and string.match returns null in the event the pattern is not found.
Report Abuse
Drak0Master is not online. Drak0Master
Joined: 10 Aug 2009
Total Posts: 836
29 Jun 2014 12:16 AM
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation
Report Abuse
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
29 Jun 2014 12:19 AM
So, for the character length. Where would i put the length to check for.
Like it needs to be 4 characters long... Its on aloop check to make sure it is 4 characters long is what i mean. So where would i out that :)
string.len(STRING) or #"STRING"
Report Abuse
Drak0Master is not online. Drak0Master
Joined: 10 Aug 2009
Total Posts: 836
29 Jun 2014 12:21 AM
#string
Report Abuse
Wehttam664 is not online. Wehttam664
Joined: 02 Oct 2009
Total Posts: 767
29 Jun 2014 12:23 AM
if (string.len("somestring")>4) then
-- CODE
end

That should check if the character count is greater than 4.
Report Abuse
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
29 Jun 2014 12:27 AM
Now ow could i mix those two, say i have little2bo3beep44

To make sure there is 4 numbers and there's numbers in it, but not in a certain order
Report Abuse
Wehttam664 is not online. Wehttam664
Joined: 02 Oct 2009
Total Posts: 767
29 Jun 2014 12:33 AM
if (string.match(thestring, '%d')~=nil) and (string.len(thestring)>4) then
-- CODE
end

Just change 'thestring' to the string your checking.
Report Abuse
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
29 Jun 2014 12:39 AM
So erm.. This is my script it still printed even tho there was one number. I meant make sure there is 4 numbers in the code. ;)

ble = "swaeg1"
--HUGE THANKS TOO :Wehttam664 Great guy ;)
--Check if there is enough letters or too much ;)
--[[if (string.len("somestring")>4) then
-- CODE
end
--Check if there is numbers in the thingie ;)
if (string.match("yourstring11", '%d')~=nil) then
-- CODE
end]]
--Check if there is numbers and there is x amount of numbers ;)
if (string.match(ble, '%d')~=nil) and (string.len(ble)>4) then
print 'hi'
end
Report Abuse
preztonizer is not online. preztonizer
Joined: 22 Oct 2008
Total Posts: 375
29 Jun 2014 12:41 AM
String
Report Abuse
Drak0Master is not online. Drak0Master
Joined: 10 Aug 2009
Total Posts: 836
29 Jun 2014 12:44 AM
local string = "I 1like2 pepperoni3 454 pizza90"
local numbers = 0
for i = 1, #string do
for o = 1, 9 do
if string.sub(string,i,i)==tostring(o) then
--code
end end end


You could make a table for the alphabet and symbols.
You could also try working with string.match()
Report Abuse
Drak0Master is not online. Drak0Master
Joined: 10 Aug 2009
Total Posts: 836
29 Jun 2014 12:48 AM
local string = "I 1like2 pepperoni3 454 pizza90"
local numbers = 0
for i = 1, #string do
for o = 1, 9 do
if string.sub(string,i,i)==tostring(o) then
numbers = numbers + 1
print(numbers) --# of numbers in string
end end end
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