Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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.
Posted 28-Apr-13 9:09am
Edited 28-Apr-13 9:11am
v2
Comments
ThePhantomUpvoter at 28-Apr-13 14:12pm
   
You could probably make use of the PadRight function to do this.
Sergey Alexandrovich Kryukov at 28-Apr-13 15:30pm
   
First, why? Second, what have you done so far?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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));
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 CPallini 155
3 PIEBALDconsult 150
4 BillWoodruff 148
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 28 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100