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

How to replace every single character in a string with a certain character?

Asked by
LazokkYT 117
1 year ago

Hi. I would like to know how I could replace a string with a character?

For example, I have a string: "Hello, this is a string"

What if I wanted to replace every single character in the string with an underscore? It would be like: "______ ____ __ _ ______"

How would I put that into a script?

I don't really know much about string manipulation. Thanks!

Like admin commands? T3_MasterGamer 2189 — 1y
Kind of? yeah LazokkYT 117 — 1y

1 answer

Log in to vote
Answered by
enes223 327 Moderation Voter
1 year ago

You can use regex to replace the characters, like "[%a%p%c]", you will just plug it in gsub and it will work. Example:

local FilterCharacter = "_"

local String = "Wow, I'm a string"
local FilteredString = string.gsub(String, "[%a%p%c]", FilterCharacter)

Answer this question