View Single Post
07/13/14, 06:12 PM   #30
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Originally Posted by merlight View Post
I find your replacement code quite convoluted Try this:
Lua Code:
  1. link:gsub("|H(%x%x%x%x%x%x)(.-|h)(.-)|h", "|H0%2|h")
  2. -- first capture matches six hex digits, which are discarded
  3. -- second capture matches everything up to and including |h, and is put in replacement %2
  4. -- third capture matches everything up to second |h (link text, discarded)
  5. -- you can use it on old and new links alike, no need to test which format you have
  6. -- on new links it wil just not replace anything, because the |Hxcolor code won't match

edit: oops, somehow I dropped one x from the pattern. fixed
Thanks, this information is appreciated. I know about the gsub routines but I have revised my code somewhat to be less repetitive but this way I know when I look at the code in 6 months time I won't have to research how gsub works again rofl. And seeing as this should be one of those one off conversion things it won't be used much.

Lua Code:
  1. if (linkData[2] ~= "0" and linkData[2] ~= "1") or linkData[2] == "0" then
  2.         local newLink = "|H1"  
  3.         for i = 3, 23 do           
  4.             newLink = newLink..":"..linkData[i]
  5.         end
  6.         newLink = newLink.."|h|h"
  7.         itemLink = newLink     
  8.     end
  Reply With Quote