Thread Tools Display Modes
01-07-11, 10:07 AM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
strsplit delimiter issue

lua Code:
  1. -- CFM_LoadBox = "Blackwing Lair - Chaosinc"
  2.         b:SetScript("OnClick", function()
  3.             -- was going to prevent reloading, but it's much simpler to just do it this time
  4.             local realm, name = strsplit(" - ", UIDropDownMenu_GetText(CFM_LoadBox))
  5.             print(realm)
  6.             print(name)
  7.         end)

This is ending up printing realm, but not the name. I'm pretty sure I'm just the delimiter, but everything I've tried so far has just screwed it up more.
  Reply With Quote
01-07-11, 10:37 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I don't see anything wrong with it...

What do you get when you do print(UIDropDownMenu_GetText(CFM_LoadBox))?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-07-11, 04:02 PM   #3
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Seerah View Post
I don't see anything wrong with it...

What do you get when you do print(UIDropDownMenu_GetText(CFM_LoadBox))?
Yeah, I know. It looks fine, but it doesn't like it for some reason.

The print() return the selected value like it should (Blackwing Lair - Chaosinc).

However, I tested this before with settings saved from my mains (Thunderlord). I just attempted the same code on my "test" realm that has two names and it prints the realm's two parts as the two returns instead.

realm = Thunderlord
returns:
Thunderlord

realm = Blackwing Lair
returns:
Blackwing
Lair
  Reply With Quote
01-07-11, 08:04 PM   #4
kraftman
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 63
trying escaping the "-"

eg
" %- "

EDIT: tested it and it doesnt work maybe use msg:match() ?

Last edited by kraftman : 01-07-11 at 08:20 PM.
  Reply With Quote
01-08-11, 01:45 AM   #5
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
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", "(.+) %- (.+)")
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
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

WoWInterface » Developer Discussions » Lua/XML Help » strsplit delimiter issue

Thread Tools
Display Modes

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