Wondering first caracter for each word in the field

  • Thread starter Thread starter Ladi
  • Start date Start date
L

Ladi

Hi all,

Is there anyway to retrieve the first character for each word from the field
formatted as text?
Example:
On the field there is "Ministry of Foreign Affairs" and we retrieve "MOFA".

Thanks in advance,
Ladi
 
Ladi

I couldn't resist. Here is a function that you can put in a global module
that can get called from anywhere in your app that will return the first
initial of every word passed to it.

So for instance: Initialize("Minister of Foreign Offices")

would return MOFO

How about: Initialize("Secretary of Baloney")
or Initialize("First Undersecretary Concerning Kitchen Ergonomics
Reorganization")

Just boggles the mind!!

Here is the code.

Public Function Initialize(strIn As String) As String
Dim strInitals As String, intPos As Integer

strInitals = Left(strIn, 1)
intPos = InStr(1, strIn, " ")
Do While intPos > 0
strInitals = strInitals & Mid(strIn, intPos + 1, 1)
intPos = InStr(intPos + 1, strIn, " ")
Loop
Initialize = Replace(UCase(strInitals), " ", "")
End Function

Ron W
 
Try something like:

dim words(10) as string
words = split ("Ministry of Foreign Affairs", " ")

This should give an array having 4 elements (Careful- I haven't tried this).
Then loop through the array:

dim acronym as string, i as int
i = 0
do until i > ubound(words)
acronym = acronym & left(words(i), 1)
i = i + 1
loop

Something like the above should do the trick. Just have to make sure the
array is sized properly.
 
Sorry Rn for the delay,

What if we need to exclude some word from showing thir first letter through
Initialise function.
Example: From "Ministry of Foreign Affairs" to retreive "MFA" excluding word
"of"?

Thanks,
Ladi
 
Ladi

All you need to do is to provide the rule(s) that works in all cases (Lotsa'
Luck) and write some code that supports it. I suspect that your One Size
Fits All rule will be difficult to conceive unless you are going to be
working with a very small vocabulary. If you can write a rule I'll take a
whack at the code. Right now my Initialize personal favorite is.

Initialize("Minister of Judicial Oversight")

Ron W

PS If you have a dictionary of these kinds of offices, tittles, positions
I'd love to get it. I can't even begin to tell you how much this tickles
me. Thanks!!!! :-)
 
Dear Ron,

I live in Albania. I don't know wether you would be interested in our
institutions.
Anyway, my personal email is (e-mail address removed). Anything you need I can
provide.

Thanks a lot,
Ladi

PS. I'm sorry but I don't know how to create a rule. To be a lawyer, I'm
good programer anyway !!! :)
 
Back
Top