Discussion:
Need help with upper case
(too old to reply)
mega_L
2009-03-25 16:08:06 UTC
Permalink
I'm stuck on my coding when I have to write a function to detect upper cases
has been used in a sentence
For example if my array element has this:
2345
SAINT PAUL
STREET
APT 5
PHILADELPHIA

I need to be able to write a code to let me know that the 2nd OR 3rd OR 5th
element is written in upper case letter

Or if I set the variable not as array, 2345 SAINT PAUL STREET APT 5
PHILADELPHIA

I need to be able to detect that at least one of the section on that street
name is written with upper case

Can anyone help please?
Azadi
2009-03-25 16:35:21 UTC
Permalink
compare() cf function performs a case-sensitive comparison of 2 strings
and returns 0 is the strings are the same. so you can compare an
uppercase version of the string to the original string, and if the
comparison returns 0 then your string is in uppercase:

<cfif compare(ucase(myarray[2]), myarray[2]) is 0>
<!--- the string in myarray[2] IS in uppercase --->
<cfelse>
<!--- it is NOT in uppercase --->
</cfif>

the above code compares the value of the second array element converted
to uppercase to the original value of the second array element. if the
result is 0, i.e. the uppercase and original strings are the same, then
you know the original string is in uppercase.

if you are dealing with a single string (which is equivalent to a
space-delimited list), then use appropriate list function to get
required list element, i.e. listfirst(), listlast(), listgetat()...

<cfif compare(ucase(listlast(mylist, " ")), listlast(mylist, " ")) is 0>
<!--- the last element in the list IS in uppercase --->
<cfelse>
<!--- it is NOT in uppercase --->
</cfif>


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
tclaremont
2009-03-25 16:44:59 UTC
Permalink
Can you describe more about what your objective is? If your objective is to
ensure that everything is in appropriate case, you could use UCASE to uppercase
everything, or LCASE to lowercase everything. If you want the first letter of
each word capitalized, you could use PROPER (I think... I might have that one
wrong).

On the other hand, if your objective is to actually detect the case of each
letter, you might have to get into determining the ASCII value of each letter
in the string. Or maybe using FIND functions.

Interesting question. I wish I could be more helpful.
mega_L
2009-03-26 16:22:20 UTC
Permalink
I'm dealing with mailing addresses stored in our db. The rule is that when the
address is printed in the envelop it should not be in all upper cases. Only the
first letter should be in upper case BUT I'm not in the position of correcting
the data I'm processing, I just need to detect and make sure they are NOT all
in upper cases. If they come as all upper cases then I return this data to my
client for them to fix.

I heard about looping through each letter and checking each with the ASCII
value but I'm afraid it would take too long to process when I'm processing
10000 or more records??????

I may have to use the technique suggested by Azadi? if this processing is
fatser than looping each letter?
Dan Bracuk
2009-03-26 16:33:30 UTC
Permalink
There is a custom tag out there called cf_capitalize. You might be able to to find it.

Alternatively, you can use list and string functions to format your address when you produce and envelope.
tclaremont
2009-03-26 19:01:57 UTC
Permalink
Without knowing your database relationship or sturcture, I can only guess, but
if you detect a problematic address in the database, and correct it unsing the
CF suggestions above, can't you also write back to the database your new,
corrected value?

With that practice, you could minimizes the potential slowness because you
would only be correcting the latest additions to the database that have not
previously been optimized.
mega_L
2009-03-26 20:24:57 UTC
Permalink
tclaremont, at this point we don't have enough man power to do things around
here. For this problem, we're doing a favor to some institution where they send
us small feed regularly and we help process the feed from them.
if they send us "bad" data, we'll return the data to them so they'll fix the
"bad" records, usually not a lot may be 10 the most then send the "good and
corrected" feed back to us. We'll insert these good data to our db but this is
for other purposes. This way we don't have to waste time fixing bad feed.
tclaremont
2009-03-26 20:36:30 UTC
Permalink
I hear that.

Back to the original problem, as I understand it, you dont want ALL letters
capitalized. But can you implement a function that just capitalizes the FIRST
letter of each word? Granted, that would result in some inappropriate
capitalization as well, but it might be a good compromise.
mega_L
2009-03-26 20:56:31 UTC
Permalink
I don't quite follow you. If the client send in SAINT PAUL STREET and I make
the first letter upper case than I'm still facing SAINT PAUL STREET, I may
have misunderstood you?
But when client send in saint paul street and I make the first letter upper
case then I'm fixing their problem which is fine if I'm fixing only this
address piece.
I'm afraid when I do this and within the feed there are other bad non address
data and if I don't fix that as well it will be inconsistent on my part for
fixing the address but not others.
Dan Bracuk
2009-03-26 21:14:43 UTC
Permalink
[q][i]Originally posted by: [b][b]mega_L[/b][/b][/i]
I don't quite follow you. If the client send in SAINT PAUL STREET and I make
the first letter upper case than I'm still facing SAINT PAUL STREET, I may
have misunderstood you?[/q]
Make the rest of the letters of each word lower case. If you can find that
custom tag, there will be a list of strings that you can keep in upper case,
such as NW
tclaremont
2009-03-27 13:38:21 UTC
Permalink
Sorry for the vague answer. I actually had the full solution in there but
edited it out accidentally while trying to make it more clear.

Take the ENTIRE string and perform a LCASE(EntireString) and then loop through
the string and UCASE the first letter of each word. By doing the LCASE first,
you are at least assured that each letter is lowercase, and can deal with the
relatively low number of exceptions from there.
Govadica
2009-03-28 08:11:25 UTC
Permalink
Thank you for info tclaremonthttp://astore.amazon.com/camelbak.bpa.free.better.water.bottle-20
Loading...