Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is rendering a part of a name possible?

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

✓ Accepted answer

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 substring method 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

2 comments

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

0

string.match is another cool one for this, though you'll need patterns

This discussion is preserved as it was. New answers, comments, and votes are closed.