如何从文本框中读取字符串并在另一个文本框中显示Unicode字符串? [英] How can I read string from a textbox and show the Unicode string in another textbox?

查看:70
本文介绍了如何从文本框中读取字符串并在另一个文本框中显示Unicode字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的程序从textbox1接收第一个字符串,并在textbox2中显示Unicode字符串.


-示例:我希望我的程序接收
之类的字符串 "Pi(\ u03a0)和Sigma(\ u03a3)."
并返回:
"Pi(Π)和Sigma(Σ)."



-当我运行此代码时,它会返回正确的结果:

I want my program to receive first string from textbox1 and show the Unicode string in textbox2.


- Example: I want my program to receive string like
"Pi (\u03a0) and Sigma (\u03a3)."
And return:
"Pi (Π) and Sigma (Σ)."



- When I run this code it returns the correct result:

textBox2.Text = "Pi (\u03a0) and Sigma (\u03a3).";
//Result: Pi (Π) and Sigma (Σ).



-此代码还返回正确的结果:



- This code also returns the correct result :

textBox1.Text = "Pi (\u03a0) and Sigma (\u03a3).";
String str = textBox1.Text;
textBox2.Text = str;
//Result: Pi (Π) and Sigma (Σ).



-但是,当我从文本框中读取字符串时,它不会转换代码,而是返回相同的字符串:



- But when I read the string from textbox it doesn’t convert the code, instead it returns the same string:

String str = textbox1.Text;
Textbox2.Text = str;
//Result: Pi (\u03a0) and Sigma (\u03a3)



我该怎么办?



What should I do?

推荐答案

您的问题是,当在文本框中输入字符串时,不会处理任何转义序列"字符,因为没有这样的东西作为文本框中的转义序列.它们是字符串文字.

如果您希望转义输入,则必须自己处理任何转义序列的字符串,删除这些序列,然后将其替换为实际字符.
Your problem is that when a string is entered into a textbox, any "escape sequences" characters are not processed because there is no such thing as an escape sequence in a textbox. They are string literals.

If you want the input escaped, you''ll have to process the string yourself for any escape sequences, remove those sequences and replace them with the actual character.


我认为您正在使用它错误的方式.不要使用任何转义序列.在文本框中完全插入Π,Σ和其他任何内容.创建一些控件插入一个字符",显示一个字符映射,让用户选择所需的字符或某些序列并将其插入.毕竟,让用户使用CHARMAP.EXE.毕竟,您为什么认为此应用程序与Windows的每个版本捆绑在一起.

取而代之的是,您只是用数字形式的代码点折磨用户,而这可能是她/他可能不理解的(甚至从您的问题来看,甚至您也不是100%理解).只是不做.

—SA
I think you approaching it in a wrong way. Don''t use any escape sequence. Insert Π, Σ and anything at all in text box as it. Create some control "Insert a character", show a character map, let the use to select required character or some sequence and insert it. After all, let the user use CHARMAP.EXE. After all, why do you think this application is bundled with every version of Windows.

Instead, you are just torturing your user with your code points in numeric form, which she/he might not understand (and even you, judging by your question, don''t 100% understand). Just don''t do it.

—SA


调整应用程序的编码,在web.config文件中为请求和响应(在system.web下)设置所需的编码

Adjust the encoding of your application, in the web.config file set the desired encoding for requests and response (under system.web)

<globalization requestencoding="utf-8" responseencoding="utf-8"></globalization>


这篇关于如何从文本框中读取字符串并在另一个文本框中显示Unicode字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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