什么是vb Chr()函数的C#等价物 [英] What is the C# equivalent of vb Chr() function

查看:101
本文介绍了什么是vb Chr()函数的C#等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将应用程序从VB转换为C#并遇到尝试复制VB Chr()函数的经典问题但收效甚微。让我看到两个事实,我希望它听起来不是粗鲁......但....


1.不,我不想使用Visual Basic Dll,将它移植到C#的全部目的是避免使用VB。


2.我试过(char)和Convert.ToChar()它们确实有效但不完全相同。让我解释一下......


在VB中,如果我做Chr(8)我会回到这个带有白色圆圈的黑色小矩形......但要弄清楚这个字符集是什么来自...当然不是ASCII ...


在C#Convert.ToChar(8)中返回/ b在我的应用程序功能中不正确,当它尝试读取此字符时它会抛出一个无效的格式异常...


任何人都可以帮忙,以便我可以使用某种类型的编码找到VB抛出的完全相同的字符...哦,我已经尝试过编码。 Default.GetBytes()

I am trying to convert an application from VB to C# and running into the classic problem of trying to replicate the VB Chr() function with little success.. let me get across two facts and I hope it doesn''t sound rude...but....

1. No I don''t want to use the Visual Basic Dll the whole purpose of porting it to C# is to avoid using VB.

2. I have tried (char) and Convert.ToChar() they do work but not quite the same. Let me explain...

In VB if i do Chr(8) I get back this little black rectangle with a white circle.... yet to figure out what character set this is from..certainly not ASCII...

In C# Convert.ToChar(8) returns /b which is incorrect in my applications functionality and when it tries to read this character it throws an invalid format exception...

Could anyone help so that I can use Encoding of some type to find the exact same character that VB throws back... Oh I have tried Encoding.Default.GetBytes()

推荐答案

ASCII / Char 8是退格。所以/ b是正确的。


一个带有白色圆圈的黑色矩形?

发布图片,这样我们就能看到你所看到的内容。
ASCII/Char 8 is a backspace. So /b is correct.

A black rectangle with white circle?
Post a picture so we can see what you see.


我知道它是正确的,但它不正确的字符集在这里是我看到的.. VB显然使用不同的编码,但我似乎无法找出什么。





I know it right, but it is not right character set here is what i see.. VB is obviously using a different Encoding but I can''t seem to find out what.
附图像
 


@DragonLord


我发现这个 Chr(VB.NET)vs char(C#)


这里绝对最低每个软件开发人员绝对必须知道Unicode和字符集(没有借口!)


我发现这个p hrase表示VB本机字符串编码是Unicode

@DragonLord
Well I found this one Chr (VB.NET) vs char (C#)

Here The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

I found this phrase which indicates that VB native string encoding is Unicode


[...],我们决定在UCS-2内部执行所有操作(两个字节) Unicode ,这是Visual Basic,COM和Windows NT / 2000 / XP用作其本机字符串类型的内容。
[...], we decided to do everything internally in UCS-2 (two byte) Unicode, which is what Visual Basic, COM, and Windows NT/2000/XP use as their native string type.



这里 .NET和C#中的字符串作者谈到unicode在一般情况下是默认的.NET

And here Strings in .NET and C# author talks about unicode being default in general .NET


编码

如本文开头所述,字符串始终采用Unicode编码。 Big-5 string的概念或UTF-8编码中的字符串或是一个错误(就.NET而言)并且通常表示对编码或.NET处理字符串的方式缺乏了解。理解这一点非常重要 - 将字符串视为以非Unicode编码表示某些有效文本几乎总是一个错误。
Encoding

As stated at the start of the article, strings are always in Unicode encoding. The idea of "a Big-5 string" or "a string in UTF-8 encoding" is a mistake (as far as .NET is concerned) and usually indicates a lack of understanding of either encodings or the way .NET handles strings. It''s very important to understand this - treating a string as if it represented some valid text in a non-Unicode encoding is almost always a mistake.



希望它有助于或至少为您提供进入的指示。


P.S.这是 http://www.fileformat。 info / info / unic ... 25d8 / index.htm


这篇关于什么是vb Chr()函数的C#等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆