View Single Post
01-08-11, 02:18 PM   #6
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Xinhuan View Post
strsplit()'s first argument must be 1 character long. If it is longer than 1 character, then ANY of the characters are treated as a delimiter. In your example

Code:
local realm, name = strsplit(" - ", UIDropDownMenu_GetText(CFM_LoadBox))
The delimeter you provided is basically " " or "-" (with " " repeated). So if you're splitting "Blackwing Lair - Chaosinc", then you end up getting the following returns:

Code:
"Blackwing", "Lair", "", "", "Chaosinc"
There are 2 empty strings there because there is nothing between " " and "-", and the second one is between "-" and " ".

If you are splitting "Barthilas - Xinhuan" then you basically get

Code:
"Barthilas", "", "", "Xinhuan"
Hence in your example code, your realm is correct, but your name is an empty string.

What you really want is this

Code:
local realm, name = string.match("Blackwing Lair - Chaosinc", "(.+) %- (.+)")
I see what you're saying there. Apparently either it wasn't noted or I missed the fact that the delimiter could only be 1 char when I was figuring out how to do this (knowing me, the latter ). Now I can finally get my profile section done.
  Reply With Quote