|
Dear all:
My Org. use a Encryption for its passwords & I have to obey it too in my App to be the same as all other App. in Org.
In this Encryption we use entered values's Ascii & ...
I can get the ASCII value of Chars as:
(int)'A' = 65 & vise versa (char)65 = 'A'
but since I use Farsi(Arabic) Chars it gives me Unicode of that char like:
(int)'ش' = 1588
Is there any way to use its ASCII & not unicode?!
Of course, I can use change Farsi entered Chars to English to get its ASCII but some of Encrypted Chars are not English letters & I have to use them!
I realy need ur help bc all App. is waiting for that Login part
Thanks in Advance & Hope to hear from u ASAP!
Always ,
Hovik Melkomian.
|
|
|
|
|
First you need to understand that all characters (and hence, all strings) are treated as Unicode in .NET (strings are even stored as Unicode in the assembly).
You can, however, use the Encoding class with the proper codepage.
See, ASCII is actually 7bit characters. Anything over 127 requires a codepage in order to resolve the symbols correctly.
To get the codepage for Farsi, you can either refer to it by the codepage, or if you don't know it do something like this:
CultureInfo ci = new CultureInfo("ar");
int codepage = ci.TextInfo.ANSICodePage; If you read the class documentation for the CultureInfo class in the .NET Framework SDK, you can find the LCIDs and culture name abbreviations (like "en-US" for "English (United States)"). For a non-regional Arabic language, you can use the LCID 0x01 (1).
So, to get an Encoding for that codepage, do this:
Encoding enc = Encoding.GetEncoding(0x04e8);
byte[] buffer = enc.GetBytes(yourFarsiString);
foreach (byte b in buffer)
Console.Write(b.ToString("x2"));
Console.WriteLine();
Here's an example of decoding a Unicode string I assume says "Hello" (in Farsi) into ANSI characters using the Farsi codepage:
using System;
using System.Globalization;
using System.Text;
class Test
{
static void Main()
{
CultureInfo ci = new CultureInfo("ar");
int codepage = ci.TextInfo.ANSICodePage;
Console.WriteLine("Using codepage 0x{0:x4}", codepage);
string str = "\ufeed\ufee0\ufe8e\ufeeb";
Console.WriteLine("Decoding " + str);
Encoding enc = Encoding.GetEncoding(codepage);
byte[] buffer = enc.GetBytes(str);
foreach (byte b in buffer)
Console.Write("0x{0:x2} ", b);
Console.WriteLine();
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear Heath Stewart:
Thanks for ur fast response & sorry for my delay! Actually I was working to fix my problem & I did as:
byte[] ubuf = Encoding.Unicode.GetBytes(c.ToString());<br />
Encoding enc = Encoding.GetEncoding(1256);<br />
byte[] abuff = Encoding.Convert(Encoding.Unicode, enc, ubuf); (But Tnx for ur code)
But now I need the opposite of that!
I mean I have ASCII now & this time I wanna have its character.
As u know values r not same since I have to make it as same as other softwares in my Office.
Example:
(char)211 = 'Ó' witch is wrong & should be 'س' Unicode 1587
Please help me about this, witch is highly appreciated!
Again tnx for code & Hello Sample;) & Sope to hear from u ASAP.
Always ,
Hovik Melkomian.
|
|
|
|
|
Then reverse what I did. This is a simple problem and you need to read about the Encoding class. I've given you plenty of information. You just use Encoding.Convert to convert from the Arabic codepage to Unicode.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok this is what I done.
Encoding ascii = Encoding.ASCII;<br />
Encoding enc = Encoding.GetEncoding(1256);<br />
<br />
byte[] asciiBytes = enc.GetBytes("س");
And I have 211 (ASCCI of unocde 1587) witch ok!
Also I have array of bytes in ASCCI mode & I wanna convert them in Unicode 1256.
byte[] unicodeBytes = Encoding.Convert(ascii, enc, asciiBytes);
Now I should have array of bytes in Unicode 1256.
And I should changethem in Strig mode so I do
char[] asciiChars = new char[ascii.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];<br />
ascii.GetChars(unicodeBytes, 0, unicodeBytes.Length, asciiChars, 0);<br />
string asciiString = new string(asciiChars);
But it gives me ? char & not 'س' Unicode 1587
Did I miss any?!
Tnx for ur time.
Always ,
Hovik Melkomian.
|
|
|
|
|
1587 has nothing to do with Unicode, mind you. It's an ASCII codepage. What you're doing is converting from ASCII (for a particular codepage) to Unicode.
If you get ? or a hollow block character, it's because the font doesn't have that character. You need to use a different font, like Tahoma or Arial Unicode MS. Unicode (and any character set, for that matter) only defines characters - not fonts.
If you're trying to print this to the console, it won't work (currently) because the console uses fixed-width fonts of a certain format.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
but already all my form's obj r in Tahoma!
I know 1587 has nothing & I just write it to say what I wanan show!
Doest my code correct to change from ASCII to Unicode or not?!
Always ,
Hovik Melkomian.
|
|
|
|
|
A glyph for character \u0633 (1587) does exist in the Tahoma font, hence the ? like I said earlier. If there's no glyph for a particular font, then you'll have to use a different font or use an image with the text, but then it's pretty static.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I Get a datatable from Database's someting table at first, then, some time after, I Get a datatable from database's same table.In my programe,I want to know this table's all records if changed. Do have some good method?
|
|
|
|
|
You can use DataSet.Merge(DataSet, bool) to merge the two DataSet s and preserve the changes. You then call DataSet.GetChanges on the same DataSet you called Merge on, and enumerate through the table(s), then enumerate the rows and check DataRow.RowState .
If you call DataSet.AcceptChanges or DataTable.AcceptChanges , these changes will be lost (the rows are resolved according to their state). Calling DataAdapter.Update on the DataSet or DataTable will call this method automatically.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an idea to submit an article about a system to license components. Since I have looked all over and have not been able to find much of real use in this area elsewhere I figured that I might as well share the knowledge a bit here since I have gotten so much from the site.
My problem is this… The code has a few issues (for lack of a better term ) that I just cannot seem to get ironed out. Not that I am not trying mind you, I just have not been able to figure it out yet. The question is this. Is it considered good (or just even ok) form to post an article that has 'issues' in hopes that:
1 - Others will benefit form the code
2 - Others might help locate what the heck I am doing wrong?
I hate to add to the chaff of the site by posting an article that will just end up confusing people in the long run.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
As a former CodeProject editor (didn't have the time anymore) and current Protector, I can assure you there's much worse articles. I'd say go ahead and post it, but make sure you point out what the problems are. Don't forget to update your article (with a history of changes at the bottom; read through some existing good articles for examples) when you've solved it and make sure you read comments in your article's forum (you should get an email automatically when anyone posts a message to your article's message board).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I've subclassed two classes inside classA. Theses subclasses are derived from classA. There are some virtual functions in classA with their implementation defined in those subclasses. Client can only see classA. Instances of classA will be created by a class factory. On basis of parameters passed to class factory, the factory creates new objects of subclasses and returns them to client. Following snippet demonstrates the idea.
<br />
public class classA<br />
{<br />
<br />
<br />
<br />
internal class subclass1 : classA<br />
{<br />
<br />
}<br />
<br />
internal class subclass2 : classA<br />
{<br />
<br />
}<br />
} <br />
1) I want to run subclass1 objects into COM+ transaction. Is it possible because client never sees subclass1 although it uses subclass1. If possible how ??
2) Is it a good practice to do things this way. The idea behind was to provide client smplicity of using one class while acheiving the logical seperation at the backend for developer's ease.
Thanks in advance,
Regards,
Hatim Ali.
|
|
|
|
|
In the System.Dialognise namespace there are many classes helping detect system error.
Now i have a big problem: Does there have a possibility to detect error from application software ?
For example, can i get a message while my office word.exe facing an error(any type of error) ?
|
|
|
|
|
Hi,
I don't know why I can' use Environment.SpecialFolder in my program.
Is it not support by Framework 1.0 ?
If not support in 1.0, then how can I get the desktop and MyDocument folder path ??
Thanks
|
|
|
|
|
You can use it. But Visual Studio 2003's Intellisense doesn't show it. You'll have to code it without the aide of Intellisense, it'll compile fine.
#include "witty_sig.h"
|
|
|
|
|
Hi
I am using C# (VS2003). I want to create an usercontrol having entry forms (ie. customers, suppliers, orders etc...) which then, I can use with a Windows Form and call New, Delete, Update, Next, Prev, Last, First, Print methods on an usercontrol within a form. Basically I want to create a base_usercontrol and base_form having some common loosly coupled methods to interect with each other. And Later on I can inherit base_usercontrol for real entry and base_form for real form operations.
I read some artical many times ago but can anyone have more information on this?
Thanks in advance
|
|
|
|
|
I am just looking a good C# example of grouping a list of data by "Date Groups" like Microsoft does in Outlook 2003 Inbox where e-mail is grouped by "date terms" like "Today", "Yesterday", "Tomorrow", "Two Weeks Ago" etc...
I started embarking on this code myself but it got complicated quickly so I thought someone smarter than me must have already tackled this one and posted a good article on how to do it somewhere - anyone know of one??? Thanks in advance!!!
|
|
|
|
|
If you're willing to wait for .net 2 then ListView has grouping ability in there.
|
|
|
|
|
Actually doing the "groups" in the ListView is not a problem (I am using Infragistics Grid Control and grouping by dates is easy…) but what I need is the function which accepts in a date, and returns a string for "Yesterday", "Tomorrow", "Last Month", etc... I know it sounds easy, but it gets pretty complicated quickly to do it right and take into account all the possibilities. For example, on the first day of the month, if you send the function yesterday’s date, the function needs to return "Yesterday" not last month. Same thing for first day of the year etc… Anyway, whenever I run into something even slightly complicated, I always figure someone smarter than me has already written some very elegant and efficient code to handle it! MS has this code for Outlook, just wondered if anyone had replicated it in a good C# example.
|
|
|
|
|
You could probably adapt
http://www.codeproject.com/cs/miscctrl/GroupListView.asp#xx824943xx
Gary
"I invented the internet".
- Al Gore, former U.S. Vice President
|
|
|
|
|
I want to underline only the first letter of text on a button control.
I don't want to use an '&' because I am--for what ever reason--using alt keys for the short cut keys for this button.
ie
this.button1.Text = "Close";
The 'C' needs to be underlined
and the short cut key is Alt-C.
thanks
|
|
|
|
|
For one, instead of hooking up shortcut keys (however you're doing that, since there's a myriad of ways), why not just use "&Close" since you're assigning Alt+C to the button? It seems a logical choice.
Really, the only other way is to owner-draw the button, but this would be tedious for such a simple requirement. Extend the Button class (encapsulating this functionality in a derivative class lets you reuse this new Button derivative without duplicating the painting code all the time in container controls) and override OnPaint . From there, there's many things you could. You could decide to paint the entire thing yourself (i.e., don't call base.OnPaint ) or call base.OnPaint first, then fill the inner portion of the control with the BackColor (so no text is shown).
Then, use the Font to create a new Font with the FontStyle.Underline style set. Use PaintEventArgs.Graphics.MeasureString to get the bounds for the first character ("C"). You'll need this shortly. Then draw the "C" with that Font . Then, using the Right property of the RectangleF you got from the first call to MeasureString , draw the rest of the text ("lose") with the original Font (the one defined on the control, since the Font for "C" is only temporary, though you might consider caching it and updating your cache in the OnFontChanged event handler for performance reasons).
This is quite a bit of work (not difficult, but tedious) for something that can be done simply with "&Close", especially since that would already use the same shortcut as what you're assigning already (unless you mean Alt+C is mapped to something else).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want one instance of an application (let's call it instance2) to get another instance (instance1) of the same application.
Instance2 already has the handle of instance1 - I've checked, and the handle's match. But in instance2, if I do :
IntPtr hdlInstance1 = [whatever I do to get the correct handle];
Control myInstance1 = Control.FromChildHandle(
hdlInstance1
);
then myInstance1 is always null. I can use Control.GetHandle(hdlInstance1) as well - that doesn't work either. Is there some special way I'm supposed to get instances by handles? I can't find any useful info online. And has anyone noticed how often code sites have the easiest, most trivial examples of a subject, like in this case, how to stop there being more than one instance of an application, but none of the sites will even dare doing something a bit more advanced like actually doing something with the second instance instead of just blocking it? It's almost like code sites just rip eachother off - one site puts up a simple example, then everyone else just copies it.
Sigh .... rantmode off.
Thanks in advance.
|
|
|
|
|
You can't create object references using handles from other processes. You need to P/Invoke SendMessage and send window messages to the other handle. This is documented in the .NET Framework SDK.
You could, instead, use .NET Remoting or some other remote procedure calling (RPC) convention, which may be easier depending on what you need to do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|