未处理的控制角色 [英] unhandled control character

查看:56
本文介绍了未处理的控制角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在从vb.net应用程序中读取Microsoft Office Word文本,然后将格式化的字符串存储在另一个ans文件中。在这个文件的某个地方,我发现了4个不可读的字符。我进入了调试模式,我发现每个字符的Asc代码都是32 !!

通常这是空格代码,虽然我使用过:

< pre lang =vb> rettext = Replace(rettext,



 rettext =替换(rettext,Asc( 32 ),  



 rettext =修剪(rettext)



但仍然没有改变rettext变量并且长度相同!!



任何人都知道该怎么办?

Thx in使用:

 rettext = rettext.Replace。 (  string  .Empty); 





请参阅: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx [ ^ ]。



(总是由于多种原因,使用 string.Empty 而不是。它应该有效。如果字符串没有更改(你100%确定吗?),它只是意味着输入字符串中没有空格字符。请注意,许多其他字符可能看起来只与空白区域相似,但却是其他字符:Em space,En space,Non-breakable space,Tab等。我希望你用空格键入,而不是别的。仔细查看输入字符串。



当然,不要尝试在.NET中使用ASCII,请参阅我对该问题的评论。更确切地说,您可以使用它,但只有在您可以通过某些特殊原因确保没有输入超出ASCII时。并了解Unicode如何工作,它不像许多人想象的那么简单。



-SA


Hi,
I am reading a Microsoft Office Word text from a vb.net app, and then storing the formatted string in another ans file. Somewhere in this file I am finding 4 unreadable characters. I went in debug mode and I found out that the Asc code of each of these characters is 32 !!
Normally this is the space code, although I used:

rettext = Replace(rettext, " ", "" )

and

rettext = Replace(rettext, Asc(32), "" )

and

rettext = Trim(rettext)


but still the rettext variable is not changed and have the same length!!

Anyone have an idea what to do ??
Thx in advance.

解决方案

To remove blank spaces from a string, use:

rettext = rettext.Replace(" ", string.Empty);



Please see: http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^].

(Always use string.Empty instead of "", by a number of reasons.) It should work. If the string is not changes (are you 100% sure?), it simply means that you don't have blank space characters in your input string. Note that many other characters may only look similar to the blank space, but be something else: Em space, En space, Non-breakable space, Tab, and more. I hope you typed " " using blank space, not something else. Look at your input string carefully.

And of course, don't try to use ASCII in .NET, please see my comment to the question. More exactly, you can use it, but only if you can, by some special reasons, guarantee that no input will be beyond ASCII. And learn how Unicode works, it is less trivial than many think.

—SA


这篇关于未处理的控制角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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