473,503 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count Unicode characters in DB2 8

Hi,

I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.

Can anybody help me with that?

Thanks in advance
kind regards
Michael

Nov 13 '07 #1
3 2510
globomike wrote:
I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.
I would write a simple Java UDF that takes the string as input and counts
the number of characters. Something like this (completely untested) should
do:

import java.lang.*; // for String class
import COM.ibm.db2.app.UDF; // UDF classes

public class UnicodeCharCount extends UDF
{
public void charCount(String str, int count) throws Exception
{
if (str != null) {
set(2, str.length());
}
}
}

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Nov 14 '07 #2
Hi!

Maybe something in the lines of:
VALUES(LENGTH(VARGRAPHIC('YOUR_UNICODE_STRING')))

Best regards,
Kovi

globomike wrote:
Hi,

I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.

Can anybody help me with that?

Thanks in advance
kind regards
Michael
--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Nov 14 '07 #3
Hi Kovi,

thanks that is what I need.
I tried it before but somehow got an error - something like
incompatible datatypes for the function...
Now I tried it again after you posted that solution and it works!

Thanks again
kindregards
Michael

On Nov 14, 4:49 pm, Gregor Kova <gregor.ko...@mikropis.siwrote:
Hi!

Maybe something in the lines of:
VALUES(LENGTH(VARGRAPHIC('YOUR_UNICODE_STRING')))

Best regards,
Kovi

globomike wrote:
Hi,
I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.
Can anybody help me with that?
Thanks in advance
kind regards
Michael

--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Nov 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
4577
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
7
8996
by: Michael Davis | last post by:
Hi, I've known C/C++ for years, but only ever used ascii strings. I have a client who wants to know how gcc handles unicode. I've found the functions utf8_mbtowc, utf8_mbstowcs, utf8_wctomb and...
18
34069
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
3
2846
by: chrisperkins99 | last post by:
It seems to me that str.count is awfully slow. Is there some reason for this? Evidence: ######## str.count time test ######## import string import time import array s = string.printable *...
14
6379
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
8
20724
by: Preben Randhol | last post by:
Hi If I use len() on a string containing unicode letters I get the number of bytes the string uses. This means that len() can report size 6 when the unicode string only contains 3 characters...
2
401
by: willie | last post by:
Martin v. Löwis: Thanks for the thorough explanation. One last question about terminology then I'll go away :) What is the proper way to describe "ustr" below? <type 'unicode'>
7
4006
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
8
2401
by: mario | last post by:
I have checks in code, to ensure a decode/encode cycle returns the original string. Given no UnicodeErrors, are there any cases for the following not to be True? unicode(s, enc).encode(enc)...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.