Help witch gsub plz guys....
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Help witch gsub plz guys....

Started by NightLitch, 16 February, 2004, 17:10:28

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

This is my single catching [VAL] code:
function Lang(string,value1)
		lang=gsub(string,"%b[]", value1)
	return lang
end

how do I make it catch all the [] in a sentence ???

ex:

Hello [USER] your IP is [IP] and you are sharing [SHARE]

how will this be done in above code.

help me out plz.

Noob on gsub.

/NL
//NL

kepp

i have no idea what you mean but ?

data = gsub(data,"%b[USER]",value1)
data = gsub(data,"%b[IP]",value2)
data = gsub(data,"%b[SHARE]",value3)
Guarding    

NightLitch

Plop, Wombat, Tezlo, Chilla could you guys help me...

Kepp's sol. didn't work so good.

wanna get this working but don't know a thing about gsub.

plz / NL
//NL

c h i l l a

#3
one way , stripped from LIS

no there are many ways ;).

kepp's only need s alittle modifing to works, well it works depending on what purpose

kepp

well i think the problem is that
you have let's say a line like this

LINE = "Hello [USER], Your IP is [IP], and you are sharing [SHARE]"

value = user.sName
value1 = user.sIP

You grab the user's Share and set that to value2..

LINE = gsub(LINE,"[USER]",value)
print(LINE)

Output : Hello user.sName, Your IP is [IP], and you are sharing [SHARE]

and you do like that till you catch all of them, might be some easier way..
I've never actually dealt with gsub so much :)
Guarding    

c h i l l a

or

LINE = gsub(LINE,"%[USER%]",value)

depending on the purpose ;)

tezlo

or..
welcomemsg = " hey [username] ([userip]) you are sharing [usershare]b"

uservars = {
	username = function(user)
		return user.sName
	end,
	userip = function(user)
		return user.sIP
	end,
	usershare = function(user)
		local s, e, share = strfind(user.sMyInfoString, "%$(%d+)%$%|$")
		return s and tonumber(share)
	end,
	-- and so on
}

function dolang(user, str)
	str = gsub(str, "%[(%a+)%]", function(id)
		local func = uservars[id]
		if func then
			return func(%user)
		else
			return id
		end
	end); return str
end

function NewUserConnected(user)
	user:SendData(dolang(user, welcomemsg))
end

NightLitch

Thx tezlo, but don't get all.

The function should be for all my text its not only for "user" could be for ex. my userinfo to. how do I make this right. with my above code.

Your code looked like I could use.

Will try it when I come home from my parents.

But more about gsub guys plz. Everything is good.

more more more.... :-) plz...

/NL
//NL

VidFamne

Isnt it so, that gsub only can replace one value at a time?
My guess is that you had to use strfind, and then substitute each value with gsub.
Only my two cent :))

tezlo

manual reads..
gsub (s, pat, repl [, n])
Returns a copy of s in which all occurrences of the pattern pat have been replaced by a replacement string specified by repl.

nl.. just make a function for it in uservars

VidFamne

Yepp, you are right, as usual. :)
Forgotten how powerful gsub is.
Sorry for my interference.

plop

check crazy bot and the next example (which is a mod from a piece of crazy).
OutputString = gsub(InputString, "(%S+)", function(word) return replace(word) end)

function Replace(word)
   if TableWichHoldsWhatYouWannaReplace[word] then
      word = TableWichHoldsWhatYouWannaReplace[word]
   end
   return word
end
with this you can replace every word in a string 1 by 1.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

NightLitch

thx alot guys. understand more now..
//NL

pHaTTy

hmm plzzzzzzzz help lol

>>> in gekko ass is replaced with another word

but if someone says pass then it changes the ass bit


how can i fix this so it only does it if its its by itself on one word
Resistance is futile!

plop

#14
QuoteOriginally posted by (uk-kingdom)pH?tt?
hmm plzzzzzzzz help lol

>>> in gekko ass is replaced with another word

but if someone says pass then it changes the ass bit


how can i fix this so it only does it if its its by itself on one word
check the hint i gave for NL, works for U 2.
my guess it that you now use a seperate gsub for everything you want 2 replace.
by using a function u can make that into 1.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

QuoteOriginally posted by plop
QuoteOriginally posted by (uk-kingdom)pH?tt?
hmm plzzzzzzzz help lol

>>> in gekko ass is replaced with another word

but if someone says pass then it changes the ass bit


how can i fix this so it only does it if its its by itself on one word
check the hint i gave for NL, works for U 2.
my guess it that you now use a seperate gsub for everything you want 2 replace.
by using a function u can make that into 1.

plop

no i use a table

["word"]="whatever",

but ill hvae a look yep :)
Resistance is futile!

Skrollster

I have realy forgotten how powerfull this language can be...

thank you tezlo for refreshing my mind :)

NightLitch

My solusion for my problem.

function Arg(str,val1,line1,val2,line2,val3,line3,val4,line4,val5,line5)
	if line1 and val1 then str = gsub(str,"%b["..line1.."]",val1) end
	if line2 and val2 then str = gsub(str,"%b["..line2.."]",val2) end
	if line3 and val3 then str = gsub(str,"%b["..line3.."]",val3) end
	if line4 and val4 then str = gsub(str,"%b["..line4.."]",val4) end
	if line5 and val5 then str = gsub(str,"%b["..line5.."]",val5) end
	return str
end

Is find this easy. Ok there is some "writings" but that it always will be.

Thx for all the help / NL
//NL

SMF spam blocked by CleanTalk