连接两个字符串,它们之间有空格 [英] concat two strings with spaces between them

查看:282
本文介绍了连接两个字符串,它们之间有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要连接两个字符串,这样第二个字符串必须从头开始放在第19位。



示例:我们两个字符串是Mumbai。 &安培; 德里。让连接发生。然后,德里的D和D。必须放在孟买第一个字母的第19位,即M。

让我们取代孟买。与加尔各答。然后在连接之后,德里的D被连接起来。必须从加尔各答的第一个字母,即K放置在第19位。



任何人都可以帮我实现这一目标吗?在此先感谢。

解决方案

您也可以使用这种方法:



  var  s1 =  孟买 ; 
var s2 = 德里;

Console.WriteLine( string .Format( string .Format( {{0}} {{1,{0}}},19-s1.Length), S1,S2));


Hi,
I need to concat two strings such that the second string must be placed at the 19th digit position from the beginning.

Example: Let us, two strings are "Mumbai" & "Delhi".Let the concatenation happen.Then, Delhi''s "D" must be placed at 19th position from the first letter of Mumbai,i.e.,"M".
Lets replace "Mumbai" with "Kolkata". Then after concatenation, Delhi''s "D" must be placed at 19th position from First letter of "Kolkata",i.e.,"K".

Can Anyone Help me to achieve this? Thanks in advance.

解决方案

You can use this approach too:

var s1 = "Mumbai";
var s2 = "Delhi";

Console.WriteLine(string.Format(string.Format("{{0}} {{1,{0}}}",19-s1.Length),s1,s2));


这篇关于连接两个字符串,它们之间有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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