View Single Post
06/04/14, 07:58 PM   #23
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 672
Let me play with it. I wana try my idea. Can you help with something?

This is the string I have, "stonefalls/davonswatch_base"
Lua Code:
  1. local count = 0
  2.     local mapParse = {}
  3.     for v1, v2 in string.gmatch (textureName, "(.-)%/") do
  4.         count = count +1
  5.         mapParse[count] = v1
  6.         d(count .. ") " .. v1)
  7.         d(count .. ") " .. mapParse[count])
  8.     end
I was looking through the lua.org stuff and could not find what I wanted. That crappy bit of code got me the first part of the string before the "/", "stonefalls" but not the second half. Then I tried your code and it's working. However, I have my doubts about my understanding of the syntax. I think I am doing it wrong and just getting lucky and they return what I want.

textureName = "stonefalls/davonswatch_base"
Lua Code:
  1. local v1, v2 = select(3,textureName:find("([%w%-]+)/([%w%-]+_[%w%-]+)"))
I get "stonefalls" and "davonswatch_base" which is exactly what I want.

textureName = "stonefalls/davonswatch_base/davonswatch"
Lua Code:
  1. local v1, v2, v3 = select(3,textureName:find("([%w%-]+)/([%w%-]+_[%w%-]+)/([%w%-]+)"))
I get "stonefalls", "davonswatch_base", and "davonswatch" which is exactly what I want.

textureName = "stonefalls/stonefalls_base"
Lua Code:
  1. local v1, v2, v3 = select(3,textureName:find("([%w%-]+)/([%w%-]+)_([%w%-]+)"))
I get "stonefalls", "stonefalls", and "base" which is exactly what I want.

Q1) Did I do it right?
Q2) Why does 3 work in all cases. I tried a 2 for the first example with only v1, and v2 and I got a number and a string.
  Reply With Quote