Mazen Elkashef
Mazen Elkashef

Reputation: 3499

My website could possibly receive both Unicode and Non-Unicode characters

A user on my website could possibly add a comment on an item that contains both Arabic and English characters. sometimes maybe just Arabic, others just English, and others French!

It's an international website you can't expect the characters being stored in my application. My website has nothing to do with the Facebook but I need my comments' TextBoxes to be able to accept and show any characters from any language!

...So how do you think I could achieve this ?

Upvotes: 0

Views: 461

Answers (4)

Mhmd
Mhmd

Reputation: 5167

First, be sure for the fields of your database that will store data may be unicode charactters change these fields to Nvarchar not varchar

and you must know that NVarchar takes double value of row ex. the maximum row size in sqlserver is 8000 character that mean when you make a field nvarchar and make it 4000 that mean you have take the all 8000 character

Second, using according to language user select in browsing, set your charset in your code or page like

read from url like http://website.tld/ar/

<meta http-equiv="Content-Language" content="ar" >
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" >

so according to change the language i n url you change the meta tags of your page and that is it and change it according to your language

Regards

Upvotes: 0

Roman
Roman

Reputation: 20246

All strings in .NET are unicode strings (see documentation of the String class for more information). So taking input from the user in a mix of languages shouldn't be a problem.

If you plan to store this information in the database you will need to make sure the database columns are of type nchar or nvarchar. As others pointed out, when you run queries against these columns out of SSMS you will need to prefix Unicode strings with N to make sure they are handled properly. When executing queries from code you should use parameterized queries (or an ORM, which would probably be better) and ADO.NET will take care of properly constructing queries for you.

Upvotes: 1

Marino Šimić
Marino Šimić

Reputation: 7342

If you use Unicode as a charset on the web pages and the database then you dont have to worry where are users from, since they will all type in unicode into your textboxes.

Upvotes: 0

Femaref
Femaref

Reputation: 61437

There are two elements here:

  1. displaying the characters - this is handled on the user side, if something is missing there the outcome will be giberish, however you can't affect that
  2. what you can affect is the way you save characters in your database - convert everything to utf-8 regardless of the input. Any popular browser is able to render utf-8.

Upvotes: 0

Related Questions