Click here to Skip to main content
11,493,948 members (64,375 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
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
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?

1 solution

Rate this: bad
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));

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 448
1 F-ES Sitecore 229
2 Nakul Chaudhari 225
3 OriginalGriff 225
4 CPallini 215
0 Sergey Alexandrovich Kryukov 10,237
1 OriginalGriff 8,730
2 Sascha Lefèvre 3,664
3 Maciej Los 3,392
4 Richard Deeming 2,500

Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 28 Apr 2013
Copyright © CodeProject, 1999-2015
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