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

how would i get the end part of the name with a script? [closed]

Asked by
MHaven1 159
5 years ago

how would i get the end part of the name with a script? so if a part is called "Part For MHaven1" how would i get the "MHaven1" part? tostring? anything helps.

2
string.sub() User#23365 30 — 5y
0
TY. MHaven1 159 — 5y
0
do you mean the end part's name? Nooberton_1 9 — 5y

Locked by User#24403

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
6
Answered by 5 years ago
Edited 5 years ago

The parameter names I used aren't the ones in the wiki, they weren't very descriptive so I made my own

sub is short for substring

string.sub(target, starting, ending) will return substring from string target starting at starting and ending at ending. Note that you don't need to provide ending, it will default to the length of the string if you don't need it.

Examples with string.sub

print(string.sub("Hello", 2, 4)) --> ell
print(string.sub("World", 1)) --> World
print(string.sub("foo bar", 2, 4)) --> oo b

If starting is negative, it will start from the end of the string rather than the start, so string.sub("Hello", -1) would return o because it is the last character.

print(string.sub("Lua", -1)) --> a
print(string.sub("strings", -2)) --> gs (last 2 characters) 

So to answer your question you might want to use string.sub("Part For MHaven1", 9)

Or you could use string patterns and find it but I think sub would be a bit easier.

0
TY MHaven1 159 — 5y
Ad