Normal Topic Acronyms (Read 850 times)
Jim_Chet
Member
*
Offline


No personal text

Posts: 6
Joined: Dec 31st, 2005
Acronyms
Feb 13th, 2013 at 8:45am
Print Post Print Post  
Is there a way to convert a string of words into an acronym?
Example: 
Element1 = Ford Motor Company
Element2 = FMC
also, I would want to leave out any non capitalized letters.
United States of America would be USA not USoA
Thanks
  
Back to top
 
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Acronyms
Reply #1 - Feb 13th, 2013 at 2:34pm
Print Post Print Post  
page 501 from the Programming Guide (Appendix 4) should get you most of the way ....

The following loop captures the contents of an alphanumeric element or variable up to
the first alphabetic character:
var vQuit as Int
var i as Int
var just_the_digits as String
vQuit = 0
i = 1
While(i <= @Len(filenumber)) And (vQuit = 0))
{
If @Asc(@Mid(filenumber, i, 1)) > 57 Then
{
just_the_digits = @Left(filenumber, i - 1)
vQuit = 1
}
}
Appendix 4 — The Standard ASCII Character Set
502
If the form element or variable contained "12345MD-D6," just_the_digits would be set
to "12345." (Compare this with @Num(filenumber) which, in this case, would return
"123456.")
You can use @Asc to loop through a string and convert all lowercase letters to
uppercase — and vice versa. This is because every uppercase letter of the alphabet is
exactly 32 lower in the ASCII table than its lowercase counterpart. (For example: "A"
= 65 and "a" = 97.) But with Sesame’s ToUpper() and ToLower() functions, you
shouldn’t have to go to such trouble.
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Acronyms
Reply #2 - Feb 13th, 2013 at 7:47pm
Print Post Print Post  
Here is an example. Place this in the on exit event for the field in question. Replace the hardcoded value "United States of America" with the field's contents, and write back to the field instead of doing a writeln on result.

Code
Select All
var str as string
var result as string
var loop as int
var length as int
var aa as string
var nn as int

// This is hardcoded for the example only
str = "United States of America"

// Initialize "result" to a blank string
result = ""

// How many characters do we need to look at?
length = @len(str)

// Loop through all the characters in the string
for loop = 1 to length
        // Get a character from the string at position "loop"
	aa = @mid(str, loop, 1)

        // Turn the character into its ASCII code number
	nn = @asc(aa)

        // Check if this in between capital-A (65) and capital-Z (90)
	if((nn >= 65) and (nn <= 90))
	{
                // If so, append it to result
		result = result + aa
	}
next

// Show the resulting string - for example only
writeln(result)

 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: Acronyms
Reply #3 - Feb 14th, 2013 at 4:30am
Print Post Print Post  
Actually it's not an acronym, it's just an abbreviation, since an acronym is a word--for instance, SATA. USB, on the other hand, is not an acronym because it is never pronounced as a word.

Do you have only a small number of different data items? In your example, if you had another record where Element 1 was Fairchild Manufacturing Company you would wind up with both records having the same abbreviation.

A related problem is where people don't always put the name in the exact same way.  Years ago I had a database that had something like four variations of Sugar Land, a city slightly south of Houston (named after Imperial Sugar, which has its headquarters there).
  
Back to top
 
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Acronyms
Reply #4 - Feb 14th, 2013 at 4:36am
Print Post Print Post  
Sugarland, TX - home of the greatest high school running back of all time - Kenneth Hall!
  

Larry
Back to top
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: Acronyms
Reply #5 - Feb 14th, 2013 at 5:13am
Print Post Print Post  
An easier way is with a For loop and @Replace(m,x,y)

@REPLACE(m, x, y)
Type: Text/String
Parameters: m as string, x (replaced) as string, y (replacement) as string
Returns: string

Basically, you want to create a function along the lines:

Function OnlyUpper(MyString) as String
    For x = 0 to 64
         MyString = @Replace(MyString, @Chr(x), "")
    Next

    For x = 91 to 255 // If you're sure there will never be codes above 127 set to 127
         MyString = @Replace(MyString, @Chr(x), "")
    Next
    Return(MyString)
End Function


An even faster way should be @RegexReplaceString(str, regular_expression, replacement , case_insensitive)
Set regular_expression to match any control, then any punctuation, then any digit, then any lower. I'm not familiar with regular expression syntax. You may be able to say "match any of these types" in a single expression.

  
Back to top
 
IP Logged