Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is rendering a part of a name possible?

Asked by
lomo0987 250 Moderation Voter
9 years ago

Is it possible to make a script that can identify only certain parts of a word? For example...

TinDrop SteelDrop IronDrop CopperDrop BronzeDrop

Can you make it identify the words before "Drop" without including the word.

While I was thinking about this and I came to a point where this might be possible based on some other scripts I have seen.. Here is my guess about how this might be done...

Have it see how many letters are in it, then remove 4. Then have it copy everything besides the last four.. I never touched about this before but I do remember a bit about other scripts I have seen that work with this stuff.

1 answer

Log in to vote
1
Answered by 9 years ago

string.find

Roblox has a neat built-in method for strings which returns the first index and last index at which a given string is found within another string. string.find

For example:

print(string.find("Hey!","!"))
--4   4
print(string.find("Four","Fo"))
--1   2

So, using this, we can actually take only the part of the string up to the 'Drop' part.

Since we are already being given the first index within the string at when 'Drop' occurs, we can just use the substringmethod for strings to get it:

local str = "TinDrop"
local find = string.find(str,"Drop")
print(str:sub(1,find - 1))
--We use -1 so we don't include the 'D'

Links

http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation#string.find

http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation#string.sub

0
oo thanks. This is exactly what i'm looking for. I'm trying to make something that can easily be made more of with a simple copy+paste. :D lomo0987 250 — 9y
0
`string.match` is another cool one for this, though you'll need patterns BlueTaslem 18071 — 9y
Ad

Answer this question