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

How do I remove part of a string?

I know how to add onto strings, it would be this for example: String.Value = "Hi"..Player.Name.."!" But how do I remove parts of a string an exmple would be I have something named "Player's_House" and I want to remove "'s_House" off of it?

1 comment

0

It's probably a wise idea to just remember the player's name in the first place (elsewhere)

1 answer

✓ Accepted answer

This is easily accomplished with patterns! The function you need is string.gsub. This function takes in a string to replace in, a pattern, a replacement string, and optionally a limit of the number of substitutions. Patterns, which are similar in function to Regex (though far more lightweight), are a way to search for various substrings based on specified information. In this case, however, you just want to search for a specific string, "'s_House", and remove it. Thus, your code would be as follows:

string.gsub("Player's_House", "'s_House", "")

Further reading on patterns: http://www.lua.org/pil/20.2.html Further reading on the string library: http://lua-users.org/wiki/StringLibraryTutorial

3 comments

0

So I would do: String.Value = String.gsub("Player's_House", "'s_House", "")

0

Is String a StringValue? That's pretty poor naming. Also, capitalization matters, it should be 'string.gsub'.

0

String is a string value..

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