?
Solved

CF Function to get number of bytes in a UTF-8 string?

Posted on 2004-03-31
6
Medium Priority
?
386 Views
Last Modified: 2013-12-24
Hi

We are extending our application to support multi-lingual characters and we've upgraded to CFMX and Oracle 9i (built with UTF-8 character sets). So, each character in my CF form will become 3 times longer when I insert it into Oracle(for Japanese Kanji) and 2 times longer for European characters.

To ensure that I do not send in a string longer than the database field to Oracle, I'd have to verify and trim the string at the CF end. I found that at the Oracle end, I can check it using the LENGTHB and trim it using SUBSTRB functions, but I'm not able to find out what the equivalent CF function is ( because CF Len function always returns the number of characters and not the number of bytes)

Any help will be greatly appreciated.

Thanks
Greg
0
Comment
Question by:netuser1976
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 10728313

Hi Greg,

There's not really an easy way to do this without consuming beau-coups resources on your server.

Basically, you'd need to look at the input from the form, and check it to see if any of the characters exceed the Unicode code 0800 (3 byte), or 0080 (2 byte), or if they are all below 0080, meaning the is data is single-byte ASCII (which, by the way, is kind of a misnomer since it's actually ony 7 bits, not 8).

You could write a UDF to do this, but like I said, I think it would be resource-intensive since you have to check every character in your string to see if it is an extended character.

Maybe a regular expression is the way to go...?

Good luck,

Seth
0
 
LVL 2

Author Comment

by:netuser1976
ID: 10728348
Yeah I agree. It would be nice if macromedia gives us a function to do this, like a LenB in VB.
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 10728438
Meybe there is a native Java class you could extend?

Check your Java documentation and see if anything jumps out...
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 6

Accepted Solution

by:
PE_CF_DEV earned 200 total points
ID: 10732519
I beleive this will work:

 <cfset varlength=len(variable.getBytes('UTF-8'))>
This should return the proper length
0
 
LVL 2

Author Comment

by:netuser1976
ID: 10743188
THANKS PE_CF_DEV. That Worked..

Thanks Seth for your thoughts.
0
 
LVL 2

Author Comment

by:netuser1976
ID: 10743290
Any way to trim the string based on the byte count..

Trim(string, 1, 4000) where 4000 is the byte count...
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question