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

How would I replace all spaces with dashes in a string?

Asked by 7 years ago
Edited 7 years ago

So I have this basic string script that I'm using for a plugin:

local string = "Hello World"
print(string)

The problem is I cant figure out how I could make it so that it detects spaces in the string and replaces them with dashes, like a url. Example: Hello World --> Hello-World. Also, is it possible to have a button that copies the string to the player's clipboard?

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

This can be done easily with string manipulation:

local i = string.gsub("hello world", "%s", "-")
print(i)

String Manipulation

PIL 20.1 – Pattern-Matching Functions

String Pattern

0
Thank you! PyccknnXakep 1225 — 7y
Ad

Answer this question