?
Solved

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

Posted on 2004-03-31
6
Medium Priority
?
378 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
What You Need to Know when Searching for a Webhost Provider
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…

777 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