字符串填充问题 [英] String padding problem

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

问题描述

使用填充下面给出的代码似乎没有发挥应有的作用,理论上,文本"ADD this text" 应该从两个字符串的第21列开始,但在str2中有一些额外的空间.在检查两个琴弦的长度时,长度竟然等于预期的20.

Using the code given below the padding doesn't seem to be playing as it should, in theory the text "ADD this text" should start from column 21 in both the strings but in str2 it has a few extra spaces. On checking the length of both the strings the length turned out to be the same 20 as expected.

        string str1 = "Test".PadRight(20);
        string str2 = "Test123".PadRight(20);

        string common = "Add this text";

        MessageBox.Show(str1.Length.ToString());
        MessageBox.Show(str2.Length.ToString());

        MessageBox.Show(str1 + common + "\n" + str2 + common);


有人以前遇到过这个问题吗?有什么明显的我想念的吗?

Anybody encountered this problem before? Is there something obvious I am missing.

非常感谢.

推荐答案

也许您的MessageBox显示的是可变间距字体?

Maybe your MessageBox is showing variable-pitch font?

尝试将字体设置为Courier New(在任何相关控件中),然后查看是否有帮助.

Try setting the font to Courier New (in any relevant control), and see if it helps.

这篇关于字符串填充问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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