【发布时间】:2016-07-30 20:51:45
【问题描述】:
我正在尝试将字符串转换为 ASCII,并添加了一个转换为 ASCII 的按钮和 2 个文本框:
我应该得到什么的例子: 对于输入 text@gg.com 我需要得到:116 101 120 116 064 103 103 046 099 111 109 出于某种原因,我总是得到 78-74-40-67-67-2E-63-6F-6D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ascii
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (char c in TextBox1.Text)
{
TextBox3.Text = Encoding.ASCII.GetString(new byte[] { });
}
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
非常感谢您的帮助!
【问题讨论】:
-
字符串已经使用 Unicode 表示,它是 ASCII 的超集。你到底想达到什么目的?是否要将字符显示为 ASCII 码序列?
-
int.Parse 将失败,除非 TextBox3.Text 包含有效数字。你需要进一步解释你到底想要做什么
-
只能将字符串的字符转换为ascii int。你的意思是:
int.Parse(c)? -
输出应该是什么样子的?
-
你真的需要在这里展示你想要做什么的例子。您是否将数字解析为字符?喜欢
65 66 67 => ABC?