Jump to content




string.gsub with 'special' symbols ( / ) [ } { ] =?!""#&¤/¤(&


  • You cannot reply to this topic
6 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 16 December 2013 - 02:57 PM

Hello.

Im working on a sandbox machine, which listen for a command, split the command by the spaces ( therefore string.gsub ), but it has to keep the symbols like "/" og "\"....

Why doesn't it do that?
Spoiler

And btw:
Does anyone know in which "folder" a sandbox is normally stored in?
like in .sys/.progs./.security/sandbox or something like that

Thanks in Advance

Edited by Mikk809h, 16 December 2013 - 03:00 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 December 2013 - 03:28 PM

Read up on Lua patterns and how to escape the special pattern characters (like ".").

#3 Goof

  • Members
  • 751 posts

Posted 16 December 2013 - 03:37 PM

Oh thanks, First I didn't know how all the patterns worked, but now i seem to have an understanding of it..

But, it seems to return 1 single string, when it was supposed to make 2 different strings ( because of the space before the /)

I used this pattern:
"%a.+"

EDIT:
by using:
"." then I receive 5 different values in the "tbl" table, but then i have to convert everything into word form, by repeating a str=str..dat["thingyWord"][num+1]
Or?

Edited by Mikk809h, 16 December 2013 - 03:42 PM.


#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 16 December 2013 - 03:49 PM

If you want to split everything with patterns then use this pattern:

%S+

%s means all space characters. When you capitalize it the pattern then finds everything except space characters.

#5 Goof

  • Members
  • 751 posts

Posted 16 December 2013 - 03:57 PM

Ahhhh! Well that makes even more sense to me.
XD I just wasted 5 mins, writing this converter xD :D
local wordBreak=false
local strTbl={}
local str=""
for k,v in pairs(tbl) do
	--print(v)
	if v == " " then
		wordBreak=true
	elseif not wordBreak then
		--print(v)
		--print(v)
		str=str..tostring(v)
	elseif wordBreak then
		strTbl[#strTbl+1]=tostring(str)
		str=""..tostring(v)
		strTbl[#strTbl+1]=tostring(str)
		wordBreak=false
	end
end

xD

Thanks!

Edited by Mikk809h, 16 December 2013 - 03:58 PM.


#6 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 16 December 2013 - 04:23 PM

View PostMikk809h, on 16 December 2013 - 03:57 PM, said:

Ahhhh! Well that makes even more sense to me.
XD I just wasted 5 mins, writing this converter xD :D/>
local wordBreak=false
local strTbl={}
local str=""
for k,v in pairs(tbl) do
	--print(v)
	if v == " " then
		wordBreak=true
	elseif not wordBreak then
		--print(v)
		--print(v)
		str=str..tostring(v)
	elseif wordBreak then
		strTbl[#strTbl+1]=tostring(str)
		str=""..tostring(v)
		strTbl[#strTbl+1]=tostring(str)
		wordBreak=false
	end
end

xD

Thanks!

Your welcome! :D

And don't forget to read my signature :P

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 December 2013 - 05:01 PM

Don't beg for votes in signatures.

Gonna have to add that bit of common sense to the forum guidelines, it seems.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users