|
Hi,
when i do this:
string unicodeString = "This string contains the unicode character";
// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
and I try to convert a Hebrew string to ascii I got in the asciiBytes
the number 69 (equals to '?')
but in english it's work just fine.
What is the problem?
Thank you in advanced,
Eran.
|
|
|
|
|
I'm a little confused about what you are trying to do here. ASCII is not capable of displaying the full range of letters for all character sets. That is one of the reasons why we have Unicode!
It seems like expected behavior to me, or at least not unexpected. If you have an international application, then you should stick to unicode only, if at all possible. Heck, you should probably stick to unicode even if you're not.
If your challenge is that you need to transmit data over a medium that only supports ASCII, consider Base64 encoding.
|
|
|
|
|
I need to convert data i got from a TCP/IP connection.. The data is a unicode string and converted to UTF-8 so that it can be sent on TCP/IP.. The data was sent on a different platform...
Now my task is to convert the data back again to Unicode...
Please help.. i tried to use the sample in MSDN on converting Unicode to Ascii.. i just modified it so that the conversion is Ascii to Unicode..
The problem is that the extended characters in the data are substituted with '?' character..
|
|
|
|
|
ASCII is not the same as UTF8. UTF8 is in fact already unicode. Sounds like you do not have to do anything? Maybe I'm missing something.
|
|
|
|
|
Here's what i want to actually...
For example the data sent was "abcdefüüü"... its a unicode string with special characters.. now the programmer(not a .NET programmer) who sent me the data said that he converted this unicode string to UTF8 first before sending it to the stream...
Now when i got the data from my side, the new string is "abcdefA¼A¼A¼"..
what i need to do is make the string back to "abcdefüüü"..
|
|
|
|
|
well ascii in israel computers the numbers between 128 - 255 its reserved to hebrew
|
|
|
|
|
See "About ASCII Encoding class" in the SDK. The encoding always results in 7 bit characters. It always excludes the extended ASCII characters, i.e. those in the range of 128-255. They will be converted as "?", which has an ASCII byte code of 63.
I do not think you can do what you want with the ASCIIEncoding class. I think perhaps Encoding.Default will work as you expect. This will return an encoding for the system's current ANSI code page. I'm not sure what that means exactly in terms of byte values, but it sounds promising.
|
|
|
|
|
I wrote about the difference between ASCII and 8-bit character sets here[^]. The encoding that the .NET Framework refers to as 'Unicode' is UTF-16 (Little Endian). The encoding referred to as 'Ascii' is ISO-646-US, a 7-bit encoding. Only the code points from 0 to 127 have any meaning; any code outside this range is simply translated to '?'.
If you want to convert an array of bytes representing characters into a System.String object, you must know what character set they represent, and what Windows code page that corresponds to. Windows code page numbers are listed at http://www.microsoft.com/globaldev/reference/WinCP.mspx[^].
For converting UTF-8 to a System.String , you can use the object returned by the System.Text.Encoding.UTF8 property.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hye,
I was wondering if any of you know if the following is possible : Run an applet, a service...which would act as an FTP client but the connection to the remote server should be initiated from the server side and not the client side! There are hundreds of good client side FTP client but no server side apparently. The reason why I'm asking is that I need an FTP client but I cannot connect to the target FTP server from the client, only from the server where the web service is running.
Thanks in advance !
|
|
|
|
|
FTP just doesn't work like that. The client must initiate the connection.
There's probably a firewall or network translator between the two which doesn't allow FTP. Talk to your administrators about opening a port in this firewall, or use HTTP for file transfer.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hye,
I know exactly what is blocked but I wanted a solution like : the web client connect to a web server and there I would run an applet/component on the server side. The server manage the FTP connection and allow basic features.
Of course the easiest solution is HTTP but I have to stick to FTP.
Not possible ? What's the reason ?
|
|
|
|
|
Mike already said it. It is simply NOT possible. Because that's not how FTP works. FTP servers 'listen' for connections and client 'connect' to server. PERIOD. If somebody gave you a requirement to stick to FTP it is just silly, because it cannot be done. Unless you do it other way around. Your app starts up an FTP Server and the server starts an FTP client and uploads a file to your client's FTP 'server', but that's just stupid.
|
|
|
|
|
I'm getting the error messsage:
"Controls created on one thread cannot be parented to a
control on a different thread."
This exception occurs when i update the grid control of the main progrm from a COM thread that i made...
I have read on other articles and forums that you need to use Control.Invoke(Delegate) function.. How do i use the .Invoke(Delegate) function? and if possible please explain the threads scenario which i am experiencing ryt now, and how does the Control.Invoke() function comes in?
Is this problem completely .NET related or do i have to Re-Marshall my COM objects again?
Another thing, there are Multiple COM threads updating the single Grid.. so how do i synchronize them?
I'm not very familiar with .Net threads so pls bear with me..
tnx...
|
|
|
|
|
it's just that you only are allowed to change a control within the thread where the control was created...thus you have to call grid.Invoke() like this:
public delegate MyDelegate void GridUpdateMethod( /* here maybe some parameters */);
it's important that the parameters you write above
must be then identical with the method - parameters where you update the grid.
and then you call:
grid.Invoke(new MyDelegate(methodname));
after that you just have to write a method (-> methodname ) where you update the grid.
public void methodname()
{
//here grid update
}
that's all. but I have no clue of COM or COM+....sorry
|
|
|
|
|
Yesterday I was trying to inherit from HttpWebRequest, to implement a protocol that extends HTTP. In the end, I think it is impossible...although the class itself can be inherited from, its main constructor is effectively private (probably declared "internal"), which means that my derived class cannot construct the base class.
This is due to the nature of the HttpWebRequest, which is always created through the WebRequest.Create() method, never directly through its constructor.
Does anyone have any experience with or insight into this?
|
|
|
|
|
How do you want to extend HTTP? If you want to add headers, you can add them to the Headers collection. If you want to use a custom verb, you can do that too: set the Method property.
If you want to customise these properties in a fixed way, and still plug in to WebRequest.Create , I think you'll have to derive a new class from WebRequest , have an HttpWebRequest as a member, and forward methods to your HttpWebRequest .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
You are right, I can add to the headers, and set the Method property. That is what I ended up doing. And it is a simpler design this way, so everything worked out for the best (so far at least).
However, I found it strange that MS would create a non-sealed class that could not be inherited. A sealed class is faster after all...and I would think that they would want the framework to be as efficient as possible.
So I figured it may just be that there is some technique that I am unaware of - I'm still a C# newbie in many ways . I'd still like to be able to inherit from it if the design evolves that way. Decorating objects (your 2nd suggestion) is usually a last resort for me, as it is always so repetitive.
[Since you asked, I am writing a 100% managed C# component for working with the client side of WebDAV. (Yes, I know that I can use MSXML). WebDAV is an extension to HTML, so it shares all the same basic characteristics. Extension equates well to inheritance, so that's why my first thought was to inherit from HttpWebRequest .]
|
|
|
|
|
The reason it cannot be inherited is because HttpWebRequest does not have a public default constructor that takes zero arguments. If you use code like this (note: not safe, you must provide proper arguments for base(..,..) ) it will compile and work:
public class SafeHttpWebRequest : HttpWebRequest
{
public SafeHttpWebRequest() : base(null, new StreamingContext()) { }
}
|
|
|
|
|
Hello ya'll,
This is my first posting so i'm not sure whether anyone out there can help me and whether or not i have picked the right forum. I'm using the .NET framework to create an application on the PDA. I'm stuck at a point where i have utilised the RDA (Remote Data Access) method and successfully "Pulled" the table "Employees" from Northwind database stored locally on my machine on SQL Server 2000. Now, the thing is i can see the tables in my PDA when i check the directory where i created the database that would incorporate "Employees" in. Now, i can't seem to actually modify this! i've used this:
Globals.conn = null;
Globals.conn = new SqlCeConnection ("Data Source = wta.sdf");
Globals.conn.Open();
Globals.cmd = Globals.conn.CreateCommand ();
Globals.cmd.CommandText = "INSERT INTO Employees (EmployeeID, LastName, FirstName) VALUES (1, 'Smith', 'Bob')";
Globals.cmd.ExecuteNonQuery();
it keeps throwing up "A duplicate value cannot be inserted into a unique index". In that case, what's the point of being able to pull the database if i can't even modify it or use it at all? Please help me... i've gone through tooo many stress balls
|
|
|
|
|
I suspect there's already an employee in the Employees table with an EmployeeID of 1, and there's a unique index on this column.
With a bit of luck, EmployeeID is an IDENTITY column and you should simply not supply a value for that column:
INSERT INTO Employees (LastName, FirstName) VALUES ('Smith', 'Bob') It's certainly an IDENTITY column in the version supplied with SQL Server 2000. I assume that these parts of the schema are synchronised with SQL Server CE.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks dude!
You are right, it was a problem with the EmployeeID being a unique index, and it being a primary key. So, i fixed it up and also did some stuff and came up with this:
Globals.conn = null;
Globals.conn = new SqlCeConnection ("Data Source = wta.sdf");
Globals.conn.Open();
//The connection is now open and now we're going to view what we've
//pulled out from the database
Globals.cmd = Globals.conn.CreateCommand();
//This would select the LastName segment of Northwind
Globals.cmd.CommandText = "SELECT * FROM Employees";
//This would then be executed and displayed on the MessageBox
Globals.rdr = Globals.cmd.ExecuteReader();
Globals.rdr.Read();
MessageBox.Show("ID Number: " + Globals.rdr.GetInt32(0).ToString() + " " + "Last Name:" + Globals.rdr.GetString(3));
Globals.cmd.CommandText = "UPDATE Employees SET LastName = 'Smith' WHERE EmployeeID = 1";
Globals.cmd.ExecuteNonQuery();
This worked perfectly, because i'm not actually changing the EmployeeID, i'm just updating the columns in reference to the primary id. Thanks dude!
|
|
|
|
|
Hi,
for an application written in C# it would be nice to have the Debug or Trace Messages shown in a textbox on a windows form.
Is it possible to redirect these messages from the standard output to , lets say to a textbox, listbox whatever?
thanks in advance
Jörg
|
|
|
|
|
Create a class derived from System.Diagnostics.TraceListener and override the Write(string) and WriteLine(string) methods. Then add an instance of this class to the Trace.Listeners and Debug.Listeners collections.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
There are also some built in TraceListeners. I often write console front-ends that listen for Trace messages and output them to the console. Its really simple:
Trace.Listeners.Add(new TextWriterTraceListener(System.Console.Out));
Probably not that useful for working with WinForms, but still a great tip
|
|
|
|
|
thanks, working fine! Very helpful....
Jörg
|
|
|
|