Click here to Skip to main content
11,575,882 members (53,761 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 8:09am
Edited 28-Apr-13 8: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 390
1 Dave Kreskowiak 204
2 F-ES Sitecore 135
3 OriginalGriff 125
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 400
4 Suvendu Shekhar Giri 365

Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | 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