Forum

> > CS2D > Scripts > String Replace
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch String Replace

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt String Replace

sixpack
User Off Offline

Zitieren
Hello, I need a quick small answer, how to replace in a string (txt) a character or phrase ("hello") with another character or phrase ("world").
Something like string.replace(txt, "hello", "world")

alt Re: String Replace

sixpack
User Off Offline

Zitieren
For some reason this does not work!
Works fine when I use strings, but it does not work when replacing using a tabled dictionary.

alt Re: String Replace

Apache uwu
User Off Offline

Zitieren
If you have a table you need to loop through all the items in the array.

1
2
3
4
5
6
7
8
replace_from={"lol","cats"}
replace_to=""

str="my cats are pretty awesome and lols"

for _,item in ipairs(replace_from) do
	str=str:gsub(item,replace_to)
end

alt Re: String Replace

sixpack
User Off Offline

Zitieren
I actually have 2 tables with 1:1 match:

table1 = {"a","b"}
table2 = {"1","2"}
a->1
b->2
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht