Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged
What is the C# equivalent of vb Chr() function
Collapse
X
-
I did this because while it is similar to the Chr() function I am asking a totally different question, I would appreciate not merging a thread when i am asking a different question on a related topic. now for further reference the value i am looking for in the Chr() function duplication is not " \u25d8" it is actually "\u0008"
so I am sure that the original answer leads me on the right track i have not been able to find the right unicode page.
Please do not merge my posts as they are seperate related questions. Thanks,Comment
-
Unicode 0008 would be ascii 8, backspace as we have been saying all along.DragonLord: is not " \u25d8" it is actually "\u0008"
DradonLord: i have not been able to find the right unicode page.
You just said you wanted unicode 0008 "\u0008" that is on this page, first column, nineth item down.
If you Google "Unicode 25d8", the third link I got was this:
Telling me the shape you describe is the Inverse Bullet out of unicode block 'Geometric shapes'Comment
-
I mean no disrespect and I am sure you are a moderator for a reason but please do a little test for me....
System.Windows. Forms.MessageBo x.Show("\u0008" );
System.Windows. Forms.MessageBo x.Show("\u25d8" );
you will clearly see that while similar they are clearly different...
what i want to do is find out where the \u0008 is being pulled from so i can find other values and return the equivalent Alt + 8 special character... just like typing in notepad.Comment
-
The Proggy fonts can be downloaded here.Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CharTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { label1.Text = label5.Text = label23.Text = "u0008"; label14.Text = label10.Text = label20.Text = "\u0008"; label2.Text = label6.Text = label22.Text = "u25d8"; label13.Text = label9.Text = label19.Text = "\u25d8"; label3.Text = label7.Text = label21.Text = "(char)8"; label12.Text = label8.Text = label18.Text = ((char)8).ToString(); label4.Text = label25.Text = label27.Text = "(char) 0x25d8"; label11.Text = label24.Text = label26.Text = ((char)0x25d8).ToString(); } } }
The nice thing is they have visual representations of control characters. As you can see, the inverse bullet character is only a circle in a box depending on the font. In most fonts that is what you will see, in keeping with the Unicode standard. But if you change to Japanese, or Proggy you may not see that character.
In MS Sans Serif a 25d8 looks very square. In Arial it looks wider than tall.
In MS Sans Serif a 0008 looks tall. In Proggy Crisp it looks like BS for backspace.
It's just up to the maker of the font.
So there is no 'function' that you need to write. If you want a unicode 8, then make a (char)8, or (char)0x0008. If you want a unicode 25d8 then make a (char)0x25d8.Comment
-
Ok this makes total sense, now if you take it one step further, how can i get the representation of label 12 to be part of a string rather than '\b'
so that i see something like this lœŠÐJ6’„¥'G when i look at the string in the watch window.. char(int).ToStr ing gives me most of the symbols the and and funny enough look different from the copy and paste in VB to here. but when i look at them in the watch window looks as I described above in label12. Is there a way i can replicate this string in c# ?Comment
-
You have the code for how all of these labels were produced.label 12 to be part of a string rather than '\b'
Code:label12.Text = ((char)8).ToString();
What the heck are you working on that you need these funky symbols *as strings*?
The only time I see this sort of thing is when someone is trying to do data transmissions like serial port, but trying to do it as string instead of doing it as bytes.
I'm really starting to think that whatever your project is, you are making 10 times more work out of it than it has to be. I suspect you are caught up in making strings out of control codes for some purpose: send to a printer or send to com port or something. If that is your end goal, then stop worrying about making strings and just send the codes as bytes.Comment
-
I was working on porting a project from VB to C# and I am unfortunately not the original designer otherwise i would have not of chosen to use a string to do as you put it strings out of control codes.
Basically it is is in the VB MD5_Crypt class that is doing a HexStrToBinStr and vise versa and int here they do the following
Code:Public Function HexStrToBinStr(ByVal StrIn As String) As String Dim StrOut As String Dim Ch As Integer Dim HexByte As String Dim ByteVal As Integer Dim ByteCh As String StrOut = "" For Ch = 1 To Len(StrIn) Step 2 HexByte = Mid(StrIn, Ch, 2) ByteVal = Val("&H" & HexByte) ByteCh = Chr(ByteVal) StrOut = StrOut & ByteCh ' MessageBox.Show(System.Text.Encoding.Default.ToString()) Next Ch HexStrToBinStr = StrOut
and
Of course it is not quite as simple as re-writing these two functions as they are also messing with the string in other areas and passing it through these two methods frequently. I am beginning to think maybe just re-writing it might be a good idea cause it seems to be so much trouble to replicate what the Chr() does by throwing back the symbol representation rather than the '\b' or '\t' etc.Code:Public Function BinStrToHexStr(ByVal StrIn As String) As String Dim StrOut As String Dim Ch As Integer Dim HexByte As String Dim HexChr As String StrOut = "" For Ch = 1 To Len(StrIn) HexByte = Mid(StrIn, Ch, 1) HexChr = Hex(Asc(HexByte)) If Len(HexChr) = 1 Then HexChr = "0" & HexChr StrOut = StrOut & HexChr Next Ch BinStrToHexStr = StrOut End Function
I do appreciate your help though, and I knew I had the code for the label, it seems that C# does some translation when you assign it to the .Text property or show it via the message box. Becasue you can't even type it as "\u0008" in a string as it throws an exception saying unkown control character...so you have to write as you know @"\u0008' and of course the string doesn't do any translation so i get the problem of reading 1 character(symbo l) at a time and when it reaches the \b or \u or \ anything it is smart enough to group it as one character but of course...compil er error states it is not in the correct format on the decode.
again thanks for the help, if you have any other thoughts it would be nice if i could just use the character symbols in a string.Comment
-
Uh... No. Look at my code again, line 24. There is no @ symbol in it.Becasue you can't even type it as "\u0008" in a string as it throws an exception saying unkown control character...so you have to write as you know @"\u0008'
It compiles and runs just fine as shown, as you can see in the screen shot of the running application.
So if you can't use "\u0008" then you have some issue beyond the terrible form of your predecessor's VB code.
As a matter of fact, if you were to use the @ symbol, then the string becomes an unprocessed literal and you will get \u0008 not a unicode 8Comment
-
Comment
-
sure send me your email i will send you my program and you can see where i am having the difficulty...I would certainly appreciate the help.Comment
-
I was trying to dynamically build the string and it doesn't like this line if you don't use a double \\ or the @ sign.. I admit in all my years i have somehow managed to avoid using the String.Format.Code:strText = String.Format(@"\u{0}" , Convert.ToString(c).PadLeft(4,(char)48));Comment
Comment