如何在字符串中添加空格 [英] How To Add Space in string
本文介绍了如何在字符串中添加空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在使用c sharp
我想添加一些空间我的字符串
在vb.net中我使用
string1 =Rose
string1 = string1 +空格(10)
c sharp中的等效空格(10)
解决方案
嘿,
您可以简单地执行以下操作:
string string1 = Rose+新字符串('',10);
请记住,字符串是不可变的,所以如果循环时间,这可能会花费很多。
对于我上面的所有其他答案:
你在那里做什么!?
你的解决方案很糟糕或不工作。
<最好的问候
代理J
如果添加对Microsoft.VisualBasic的引用(在microsoft中),您可以在C#中执行相同操作。 visualbasic.dll)见这里:
http://msdn.microsoft.com/en- us / library / microsoft.visualbasic.strings.space%28VS.80%29.aspx [ ^ ]
如果您不想添加此引用,只需使用:
string1 + =;
为字符串添加空格后缀:
string char = Codeproject;
string padright = char .ToString()。PadRight( 10 ,' ');
为字符串添加空格前缀:
string char = CodeProject上跨度>;
string padleft = char .ToString()。PadLeft( 10 ,' ');
Hi All,
I am using c sharp
I want to add some space in my string
In vb.net i use
string1="Rose" string1= string1+space(10)
What is the equivalent space(10) in c sharp
解决方案
Hey,
you can simply do the following:
string string1 = "Rose" + new string(' ', 10);
Please remeber, strings are immutable so this can cost a lot if time in a loop.
For all other answers above me:
What are you doing there!?
Your Solutions are terrible or not working.
Best Regards
Agent J
You can do the same in C# if you add a reference to Microsoft.VisualBasic (in microsoft.visualbasic.dll) see here:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.space%28VS.80%29.aspx[^]
In case you don't want to add this reference simply use:
string1 += " ";
Add space suffix to the String:
string char= "Codeproject"; string padright= char.ToString().PadRight(10, ' ');
add space prefix to the string:
string char= "Codeproject"; string padleft=char.ToString().PadLeft(10,' ');
这篇关于如何在字符串中添加空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文