-1

I am going to write a simple console app in C# that replaces all Latin based characters with their respectively defined replacedment (like Å (ALT+143) becomes AA).

I was wondering how it is viewed in C#. Would it be seen as the string "\uC5" or "\u00C5" or "Å" or something else?

dalawh
  • 886
  • 8
  • 15
  • 37
  • Hello and welcome to SO! Please read the [FAQ](http://stackoverflow.com/help/how-to-ask) on how to ask a good question. In the meantime you can provide us with some code showing what you have tried so far. –  Oct 31 '13 at 14:36
  • Explain what you mean with _"how it is viewed in C#"_. – CodeCaster Oct 31 '13 at 14:37
  • possible duplicate of [How to write unicode chars to console?](http://stackoverflow.com/questions/5750203/how-to-write-unicode-chars-to-console) – CodeCaster Oct 31 '13 at 14:39
  • You need to be more explicit. C# is not a text visualisation system, it's a programming language. – R. Martinho Fernandes Oct 31 '13 at 16:00
  • @CodeCaster It is not the same as the question asked in the linked you shared. I was just trying to understand how C# reads/understands/views latin based characters. As humans, we see it as a series of characters, what does the compiler see it as, which I have now found the answer to. – dalawh Nov 01 '13 at 12:22
  • That is why I asked for clarification on what you mean by _"How it is viewed"_. Now you name "compiler" for the first time, which renders the accepted answer incorrect. The compiler sees characters in .cs files _as they are in the file_. If you type `"\uNNNN"`, the compiler reads a string of six characters: `\uNNNN`, and will parse that into an Unciode character. If you _type_ a character like `☺` (\u263A) and save the file in an Unicode encoding like UTF-8, the compiler sees one character: the one you typed. The compiler operates on text files, so what you see in there is what you get. – CodeCaster Nov 01 '13 at 12:56
  • So, I don't know what you can do with the currently given answers. It could really prove helpful if you could explain your actual problem, like _"How do I compare Unicode characters?"_ or whatever it is you're trying to do. – CodeCaster Nov 01 '13 at 13:00
  • @CodeCaster I was trying to replace Latin based characters with their respectively defined replacement. So if there is Å and I say I want to replaced all Å with AA, then I search through the string for Å and replace it with AA. Ex. ÅBBÅBBB becomes AABBAABBB. Before I could do that, I had to first understand how Å was represented. – dalawh Nov 01 '13 at 13:33
  • _"Before I could do that, I had to first understand how Å was represented."_ - From your description and comments it still isn't clear what you mean, nor does it seem relevant to the compiler. I guess all you wanted to know is the [`char` structure](http://msdn.microsoft.com/en-us/library/system.char.aspx). Anyway good for you you got this sorted out. – CodeCaster Nov 01 '13 at 13:43
  • @CodeCaster May I ask why you sound as if you are mad? I mean if you aren't here to help people, why post? I understand that I wasn't as clear as you wanted me to be, but you have to realize that I don't understand the material as well as you do. – dalawh Nov 01 '13 at 14:49
  • I'm absolutely not mad, I just tried to understand your problem so it can be worded in a way that is useful for other readers. :) I mean - if you could perhaps have shown a bit of code and explain what that code is supposed to do, it would be a _lot_ more clear than _"How does C# view Unicode"_. :) – CodeCaster Nov 01 '13 at 14:50

2 Answers2

1

It is (almost!) always viewed as a character literal in format "\u00C5".

See this article on Char.

and this article specifically on character literals which, while outdated, still applies in the latest version of .NET.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Alex Walker
  • 2,337
  • 1
  • 17
  • 32
1

C# strings are Unicode, so it will be shown as is

VladL
  • 12,769
  • 10
  • 63
  • 83