|
| 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 |
|
|
|
| 15 Aug 2013 07:35 PM |
Have you looked at the wiki?
http://wiki.roblox.com/index.php/Function_Dump/String_Manipulation
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|