[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  disassemble strings

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: disassemble strings
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Couto   (15 posts)  [Biography] bio
Date Sat 25 Feb 2012 10:33 PM (UTC)  quote  ]
Message
thanks a lot Nick
[Go to top] top

Posted by Nick Gammon   Australia  (18,800 posts)  [Biography] bio   Forum Administrator
Date Sat 25 Feb 2012 10:15 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Couto   (15 posts)  [Biography] bio
Date Sat 25 Feb 2012 07:48 PM (UTC)  quote  ]

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
[Go to top] 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.


699 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]