Thread Tools Display Modes
11-02-08, 06:53 PM   #1
Demeth
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 3
Converting a phrase to an acronym

Code:
function Acrobot_SubChecker(msg) 
	local SubStatus = nil
	local UnconvertedAcro = msg
	DEFAULT_CHAT_FRAME:AddMessage("Unconverted Acro:" .. UnconvertedAcro) --This successfully displays the phrase being passed to the function
	local ConvertedAcroTable = {}
	for part in string.gmatch(UnconvertedAcro, "%a+") do
		AbbreviatedAcro = string.sub(part, 1, 1)
		table.insert(ConvertedAcroTable, AbbreviatedAcro)
	end
	ConvertedAcroString = table.concat(ConvertedAcroTable)
	DEFAULT_CHAT_FRAME:AddMessage(ConvertedAcroString .. " " .. Acrobot_CreateAnswer("current")) --This is where it fails with the error "attempt to concatenate a nil value"
	if string.lower(ConvertedAcroString) == Acrobot_CreateAnswer("current") then		
		SubStatus = "Accepted"
		return SubStatus
	elseif string.lower(ConvertedAcroString) ~= Acrobot_CreateAnswer("current") then
		SubStatus = "Rejected"
		return SubStatus
	end
end
The code I pasted above is intended to take a phrase and convert it into an acronym. For example, the phrase "Demeth likes WoWInterface" would become "dlw". However, it's refusing to work, and I'm out of ideas.

This is my first "real" addon by the way.
  Reply With Quote
11-02-08, 07:21 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The way that I would do it would be to split the string wherever a space occurs, then take each word and chop off everything but the first letter. Then you'll need to put them back together, and string.lower or string.upper depending on how you want it formatted.

Code:
local phrase = "Dameth likes WoWInterface"
local words = {strsplit(" ", phrase)}
local letters = {}
for i = 1, #words do
     letters[i] = strsub(words[i], 1, 1)
end
local abbr = strconcat(unpack(letters))
The above is *totally* untested and not written by a pro.
__________________
"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


Last edited by Seerah : 11-02-08 at 07:30 PM.
  Reply With Quote
11-05-08, 08:07 PM   #3
Demeth
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 3
It works, thanks!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Converting a phrase to an acronym


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