473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to validate a string containing Chinese?

Hi All,

I want to validate a string, and see if it contains any Chinese character
(simple or traditional). I'm trying to use RegExp and Encoding, but no
result.
Can someone point me a direction?

Kind regards,
Kevin
Dec 20 '05 #1
2 5115
Hi Kevin,

I am not sure why you would need the Encoding class. All strings are
internally Unicode in .NET (unless you are dealing with _byte_ arrays).
Therefore, what I think you need first is to determine what range(s) of
numeric character codes constitute all the Chinese hieroglyphs. Then, just
define an RegExp pattern that would capture all such characters, for
example, if there are just two ranges:

[\uXXXX-\uYYYY]|[\uZZZZ-\uWWWW]

(of course XXXX must be numerically less than YYYY, the same goes for ZZZZ
and WWWW).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Kevin" <ke***@home.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi All,

I want to validate a string, and see if it contains any Chinese character
(simple or traditional). I'm trying to use RegExp and Encoding, but no
result.
Can someone point me a direction?

Kind regards,
Kevin


Dec 20 '05 #2
Kevin <ke***@home.nl> wrote:
I want to validate a string, and see if it contains any Chinese character
(simple or traditional). I'm trying to use RegExp and Encoding, but no
result.
Can someone point me a direction?


Dmytro gave a regular expression solution - I'd just hard code it,
personally. Just iterate through each character in the string, and
check whether it's in the range you're interested in. Personally I
think that's a bit more readable than the regular expression solution,
although if there are lots of ranges to consider, a regular expression
formatted on multiple lines with a range and a comment on each line
might be better than a hard-coded solution. (The hard-coded solution is
likely to be faster too, but I wouldn't worry about that until you've
determined that it's actually a performance bottleneck.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '05 #3

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

Similar topics

1
by: michaelpyles | last post by:
I have the following URL that was HTML encoded in my web page: <a HREF="transfer/rad0/﨨.jpg" TARGET="_blank">﨨.jpg</a> I am attempting to download this file which is simply one chinese...
0
by: lungwahchong | last post by:
Hi, I have these strings which are pulled from a database which contains both english and chinese characters(big5). e.g. Fragrant Rice 10kg Green Dragon???? Broken Rice 10kg G.Elephant...
4
by: mikeyjudkins | last post by:
I have an XML file containing localized strings in 9 languages, encoded in Unicode (UTF-8). Im trying to parse this XML document via XSLT (Apache Xalan) to selectively render localized strings...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
1
by: accessyou | last post by:
I am using a windows 2000 with apache and php5 A simple url submit containing only english characters are OK: http://www.abc.com/submit.php?msg=test If the value of msg is replaced with a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
3
by: c676228 | last post by:
Hi everyone, I just realized that it's so important to validate each string, I mean 'each' before you insert data from asp page into database. I guess some customers just copy data from some...
3
by: Lord0 | last post by:
I *think* I need to be able to validate subsets of an XML document using different schema. The functionality I'm trying to implement is this. a) External suppliers produce an XML document...
2
by: lookon | last post by:
I have a string a(for example, a='¤¤¤åChinese'), and I want to know whether there are some Chinese in the string. Can someone tell me how to do it? Thanks!
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.