|
What does this have to do with C#? If you were using C# (or .NET in general) you shouldn't be using Winsock but the System.Net classes, like the HttpWebRequest , or more simply the WebClient , to retrieve a web page. Unnecessarily interoperating with native code (like Winsock) creates security dependencies that may or may not be granted to your code.
What is it exactly that you're asking? Do you want to show a Unicode (not all caps, BTW) character as س, or resolve س to a Unicode character?
If you understand HTML (or actually SGML that defines entities like this), it should be simple. The representation above is a decimal (base 10) representation. If you see an x, like س, then it's hexadecimal (base 16). In either case you could parse the number, convert it to hex (if necessary), then split it into 2 characters (2 hex digits). Use the UnicodeEncoding.GetString or UnicodeEncoding.GetChars to covert that byte[2] array into a char (in .NET, a char is always stored in Unicode) or a string (again, always stored in Unicode internally).
mirzaei wrote:
if you can help me please send your solution to my mail box : mirzaei@gmail.com
All forums on Code Project are message boards. Direct email is not encourage and should not be expected. If you entered your address correctly into your profile you will receive notification email by default when someone replies to you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
If you need to convert a Unicode character to that representation, then it's quite easy. Use UnicodeEncoding.GetBytes to get a byte[] array, then loop over that byte[] array and print either decimal or hexadecimal.
The following example loops in 2-byte increments and prints a decimal format:
using System;
using System.Text;
class HtmlEntities
{
static void Main(string[] args)
{
if (args.Length > 0)
{
Console.WriteLine(HtmlFormat(args[0]));
}
}
static string HtmlFormat(string value)
{
StringBuilder sb = new StringBuilder(value.Length * 7);
Encoding enc = Encoding.Unicode;
foreach (char c in value)
{
byte[] buffer = enc.GetBytes(new char[] {c});
int i = BitConverter.ToInt16(buffer, 0);
sb.Append("&#" + i.ToString() + ";");
}
return sb.ToString();
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have to render to screen images that come from a variety of sources (such as faxes, etc.), and some of those images are TIFF files with YCbCr encoded Jpegs. Unfortunately, .Net doesn't handle these kinds of images.
I need some help understanding how to decode a jpeg. I have enough code to take apart the TIFF, and I have some sample code which will translate YCbCr values into RGB values, but I could really use some help with decoding the jpeg itself.
Any pointers?
|
|
|
|
|
You need to read it manually ? If you just read it in, the byte array won't read in with YCbCr values ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Well, even if I read it in manually, it's compressed. That's the trick: how do I handle jpeg compression? Jpegs aren't stored in a simple pixel-by-pixel format. Or... so I gather.
|
|
|
|
|
C# can read a number of formats, including jpeg, and give you a byte array. Read my image processing articles for more info.
So, if the jpeg just contains YCbCr instead of RGB, it would be a simple case of reading the file, iterating over it, and converting each pixel to an RGB value.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I think that there's something broken in the image I was testing with. I have a single-page TIFF which I can extract a YCbCr encoded jpeg from and open with a .Net bitmap. Thanks for the help!
|
|
|
|
|
Hi All,
I added a C# class file to the C# project.
I want to use the drop down control at runtime. I get an error when I write
using System.Web.UI.WebControls;
on top of the page. Can't we not use it?? How do I access any control at runtime in a class. Please let me know.
Thanks.
|
|
|
|
|
You're probably trying to use web controls in a project that has not imported the dll that contains them
But that's a wild guess, seeing as you've not told us the error.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks. The error is
The type or namespace name 'UI' does not exist in the class or namespace 'System.Web' (are you missing an assembly reference?)
|
|
|
|
|
Yep - I'm right then. I'm not sure if you can use the web controls outside an ASP.NET project. They work by generating HTML in conjuction with the ASP.NET ISAPI filter, you realise that, right ? What's wrong with the Windows controls ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks. Ok, now I just converted a code from VB.net class file to a C# class file. This works fine in VB.net. But it gave error here.
|
|
|
|
|
OK, in that case your converter sucks. Just add the reference ( there's a references section on the top of the project, just right click and choose add reference, and look for System.Web, or whatever it is you need ) and you should be fine.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks a lot.
I have added the statment:
using System.Web.UI.WebControls;
I no longet get the error. But when I write using System. I don't see "Web" in the intellisense. Why?? ANy idea.
|
|
|
|
|
Intellisense is unreliable at the best of times - don't worry about it.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Cool!
I have another Q, how do I create an ascx file for a user control.
When I click on "Add user control", I get a xyz.cs file and not ascx file.
This is the last Q...
|
|
|
|
|
There are two types of controls, one that has an ascx, and one that is code only. Make sure you're creating a 'web user control'.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
How do I add the ascx file? If I add the Usercontrol file, I get .cs extension file. I then change the extension to .ascx but I can't view the code. What am i doing wrong.
This is really bugging.
|
|
|
|
|
Changing the extension would be a dumb thing to do. For starters, you need a .cs file in a user control as well.
Like I said, if I right click on the project and choose 'Add Web User Control', I get an ascx. It's a custom control that doesn't have an ascx file. There is something very screwy about your setup, or how you're going about this.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
You probably have a Windows Forms project when you want an ASP.NET project. Can you verify that?
How to know: select the project name in the Solution Explorer. The property window should have only two items, project file and project folder. Project folder should be disabled. If project folder is a normal path, it's a Windows Forms project. If it is a URL (http://localhost....) it's an ASP.NET project.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Where would I place a .config file for a windows serice? Would it only be used when I install the service or would it be used everytime the service was started?
Cheers,
Jim
|
|
|
|
|
The .config is always opened when the corresponding executable tries to access it and will have to be positioned at the same location as the executable.
(I assume you mean the "myProgramName.exe.config" file)
|
|
|
|
|
Yes, that's exactly what I meant. I just don't know where exactly the executable sits when its a service. I suppose it doesn't actually go anywhere and calls the same one anyways? Should I just install the service as per usual?
Cheers,
Jim
|
|
|
|
|
When you install your app as a service the current executable path is used, and the same executable path is used every time the service is started.
mav
|
|
|
|
|
Oh Really? That would mean that i only have to recompile a file after I have installed it, as opposed to uninstalling and reinstalling the file every time.
Thanks,
Jim
|
|
|
|