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.find and string.sub

Previous Thread :: Next Thread 
Saviorofdragons is not online. Saviorofdragons
Joined: 10 Jan 2013
Total Posts: 489
15 Aug 2013 07:32 PM
I am working on an admin commands script and I have looked over other admin scripts to see what they include, I get most everything but these 2 things. Could someone please explain what these do and what they can be used for?
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
15 Aug 2013 07:35 PM
Have you looked at the wiki?

http://wiki.roblox.com/index.php/Function_Dump/String_Manipulation
Report Abuse
Saviorofdragons is not online. Saviorofdragons
Joined: 10 Jan 2013
Total Posts: 489
15 Aug 2013 07:39 PM
I have looked at the wiki, and it answers some of my questions, but not all of them. I am still not getting string.find I think I have gotten string.sub down but I came here to make sure what I thought was right.
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
15 Aug 2013 07:40 PM
string.sub(string, start, finish) returns the portion of the string from start to finish. For example:

print(string.sub("Hello!", 2, 4))
print(string.sub("Hello!", 2))
print(string.sub("Hello!", 5, 6))
> ell
> ello!
> o!

string.find(string, word) will search string for word, and return where it is found. For example:

print(string.find("Why hello there!", "hello"))
> 5, 9

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
Saviorofdragons is not online. Saviorofdragons
Joined: 10 Jan 2013
Total Posts: 489
15 Aug 2013 07:43 PM
Oh ok, I see. What I thought was string.find checked a string for a word or something and returned true or false based on if it found it or not. Don't even ask how I came up with that, because I will have no answer.
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
15 Aug 2013 07:45 PM
Sorry if my explanation does not help you because I'm bad at explaining q-q.

String.sub will return part (or all) of a string.
Ex:
a = "sub"
print(string.sub(a,1,2))
--prints "su" the first to second letter
Note: if you use a negative number as in this example, -1 will be the last character of the string, -2 will be the second to last, and so on.

String.find will return the location of the string you're trying to find within a string if it's there.
Ex:
a = "suuuuuuuper"
print(string.find(a,"su"))
--prints "1 2" because su can be found in the string at the first to second character
Note: if it's not there, it will return nil
Report Abuse
sam8985 is not online. sam8985
Joined: 12 Nov 2011
Total Posts: 582
15 Aug 2013 07:48 PM
If you wanted something like that, just do:


A = "stringhere"
ToFind = "findstringhere"
local Found = false
function findword(string,find)
if string:find(find)~=nil then return true end
return false
end

if find(A,ToFind) then local Found = true else local Found = false 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