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

What do I do about gsub not formatting properly?

I have the code

string = string:gsub("-  - ", "=   ")

to take the string

| - - |

and turn it into

| = |

but it always comes out as

| = = |

and I don't know how to fix it.

1 answer

✓ Accepted answer

Try this pattern

string.gsub("|--||--||--|--|", "%-%-", '=')

Your attempt does not work because - is a magic pattern in string formatting which is described in the wiki as match as few of the preceding character class as possible, since you need to replace the - character instead, you need to use the % operator which turns any special character after it into just a character.

1 comment

0

I had tried "%-" but didn't consider the fact that it needed to be applied to all of them. Thank you!

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