在 JavaScript 中写出 null

发布于 2024-08-11 07:02:20 字数 461 浏览 3 评论 0原文

这个问题是这个问题的后续问题:write binary data using JavaScript on服务器

仅使用 Response.Write 写入字符串的问题是该字符串包含一个空字符,JavaScript 将其识别为字符串的结尾。

我尝试编写的字符串以以下内容开头(此处以字符代码编写),

255 216 255 212 0 16 ...

JavaScript 只会在此处输出前 4 个字符,因为它将第 5 个字符识别为字符串终止符。有什么办法解决这个问题吗?


我应该注意,我确实必须写出二进制 null...它的输出是 pdf,所以我无法更改输出格式。

This question is in follow up to this one: write binary data using JavaScript on the server.

The problem there with just using Response.Write to write the string is that the string contains a null character which JavaScript recognizes as the end of the string.

The string I'm trying to write starts with the following (written here in character codes)

255 216 255 212 0 16 ...

JavaScript will only output the first 4 characters here, because it recognizes the 5th as a string terminator. Is there any way around this?


I should note that I really do have to write out the binary null... the output of this is pdf, so I can't change the output format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风月客 2024-08-18 07:02:20

对数据进行 Base-64 编码怎么样?
当然,您需要对其进行解码。

What about base-64 encoding the data?
You'll need to decode it of course.

時窥 2024-08-18 07:02:20

您应该能够将空对象直接传递到 Write 函数中,并使其输出与空字符串相同,不应该出现运行时错误。因此,以下代码不会向屏幕返回任何内容:

protected void Page_Load(object sender, EventArgs e)
{
    string str = null;
    Response.ContentType = "text/plain";
    Response.Write(str);
    Response.End();
}

You should be able to pass a null object directly into the Write function and have it output the same as an empty string, there should be no runtime errors. Thusly the following code will return nothing to the screen:

protected void Page_Load(object sender, EventArgs e)
{
    string str = null;
    Response.ContentType = "text/plain";
    Response.Write(str);
    Response.End();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文