Solved

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

Posted on 2004-03-31
6
374 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
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 
LVL 6

Accepted Solution

by:
PE_CF_DEV earned 50 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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