Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ disassemble strings

disassemble strings

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Couto   (15 posts)  Bio
Date Sat 25 Feb 2012 07:48 PM (UTC)

Amended on Sat 25 Feb 2012 07:52 PM (UTC) by Couto

Message
Hi guys,

this weekend i got totally dragged into experimenting with ATCP and now i'm trying to disassemble a string and use only different parts of it.

the string i want to disassemble:
roomid = "raum/e4fdca13e0ce2426c14221923d632606 Nereid x=32 y=3"

Now i want to split it into following variables:
id = "raum/e4fdca13e0ce2426c14221923d632606"
area = "Nereid"
coordx = "x=32" --> maybe coordx = 32
coordy = "y=3" --> maybe coordy = 3

I tried the following 2 things which both didnt work. Either not usable for my intention or i'm not using it correctly.


  coordx = string.match(roomid, "x\=\d+")
  Note(coordx)
--> should search for x=32 in the string?

  for id, gegendname, coordx, coordy in string.gmatch(roomid, "(%raum\/\w+) (%w+) (%x\=\d+) (%y\=\d+)") do
  Note(id)
  Note(gegendname)
  Note(coordx)
  Note(coordy)
end
--> should disassemble the string completly in pieces?


Can anyone give me a short example how i can do this and maybe a explanation why my tries didnt suceed?

Edit: i forgot to mention that i only really need area, coordx and coordy
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 25 Feb 2012 10:15 PM (UTC)
Message
You seem to be mixing a few styles here. The Lua regular expressions use %x rather than \x and so on.

This breaks up your string:

roomid = "raum/e4fdca13e0ce2426c14221923d632606 Nereid x=32 y=3"

local id, gegendname, coordx, coordy = string.match (roomid, "(raum/%x+) (%w+) x=(%d+) y=(%d+)") 

if id then
  Note(id)
  Note(gegendname)
  Note(coordx)
  Note(coordy)
else
  print ("no match")
end


Output:


raum/e4fdca13e0ce2426c14221923d632606
Nereid
32
3


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Couto   (15 posts)  Bio
Date Reply #2 on Sat 25 Feb 2012 10:33 PM (UTC)
Message
thanks a lot Nick
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,415 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.