字符串格式和十六进制字符 [英] String format and hex chars

查看:515
本文介绍了字符串格式和十六进制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么这不工作:

can someone explain why this doesnt work:

string f = string.Format("\\x{0:00}{{0}}", 5);
string o = string.Format(f, "INSERT TEXT");
System.Diagnostics.Debug.WriteLine(f + " : " + o);

输出是:

\x05{0} : \x05INSERT TEXT

为什么用\\ \\x05不会被替换?

why does the \x05 not get replaced?

推荐答案

有关应在格式说明中设置的参数的格式,否则你只是插入文字\x。像这样的:

The format for the argument should be set in the format specifier, otherwise you're just inserting a literal "\x". Like this:

// "5" as a lowercase 2-digit hex
string f = string.Format("{0:x2}{{0}}", 5);



不要混淆你怎么代表在源代码中的文字十六进制与你在一个格式化的打印什么串,它们是不同的事情。

Don't confuse how you represent a hex literal in source code with what you would print in a formatted string, they are different things.

这篇关于字符串格式和十六进制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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