Ad
Log in to vote
0

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

Asked by
LazokkYT 117
15 days 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!

0
Like admin commands? T3_MasterGamer 845 — 15d
0
Kind of? yeah LazokkYT 117 — 15d

1 answer

Log in to vote
3
Answered by
enes223 312 Moderation Voter
15 days 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)
print(FilteredString)
Ad

Answer this question