Thread Tools Display Modes
05-10-09, 03:33 AM   #1
Kayja
A Deviate Faerie Dragon
Join Date: Jan 2009
Posts: 19
item strings and match/sub/find

If possible, could anyone please help me with patterns for .match .find or/and .sub as I just cannot understand patterns properly. What I basically want is a function that can rip the item name and item ID from a string regardless of what's in it. Such as:

"I wanted to go outside side today but instead I stayed in and got a new [Fancy Item of the Eagle] for my Warlock!"

"[Fancy Item of the Eagle]"

"You receive loot: [Fancy Item of the Eagle"]

"skdglksdhglkshdlgdshlgslkgsdg[Fancy Item of the Eagle]kdsflksdhg"

I just want, at the end, to have to variables (ie. iName and iID) which hold the item's name and item's ID.

I've tried lots of things, I managed to get a pattern working for "You receive loot: [Blah]" however the same pattern doesn't work for when I just link the item into the function rather than a full string with various words. I assumed it would have found it regardless of whatever was in the string I provided, since it gets parsed as Hitem:x:x:x:x and so forth, but for some reason I cannot get it to work.

What I have at the moment is:

Code:
function getItemID(item)
	local iName, iID = string.find(item, "item:(%a+):(%d+):(.*)")
	if ( iID == nil or iName == nil ) then
		return "Couldn't get it";
	else
		return iName.. " + "..iID;
	end
end
The return of his function is inside a DEFAULT_CHAT_FRAME:AddMessage so it'll print out.

Help very much appreciated
  Reply With Quote
05-10-09, 04:22 AM   #2
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Code:
ItemID, ItemName = strmatch(StringToMatchHere, "|Hitem:(%d+):%d+:%d+:%d+:%d+:%d+:%d+:%d+:%d+|h%[(.-)%]")
  Reply With Quote
05-10-09, 04:23 AM   #3
Kayja
A Deviate Faerie Dragon
Join Date: Jan 2009
Posts: 19
Brilliant, thanks a bunch!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » item strings and match/sub/find


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off