how to display output [Resolved]

Posted by Gow.Net under C# on 3/6/2012 | Points: 10 | Views : 2150 | Status : [Member] | Replies : 4
My input
string str1="dotnet";
string str2="FUNDA"
;
how to display above input to following format
" dFoUtNnDeAt "

gowthaman8870226416


Responses

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi Gov, take this:

char[] str1 = "dotnet".ToCharArray();
char[] str2 = "FUNDA".ToCharArray();

string output = "";

for (int k = 0; k < str1.Length; k++)
{
int j = k - 1;
output += str1[k].ToString();
if (j >= 0 && j < str2.Length)
output += str2[j].ToString();
}
Console.WriteLine(output);


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi this is not possible directly but you can do it like:

char[] str1 = "dotnet".ToCharArray();
char[] str2 = "FUNDA".ToCharArray();
string output = "";

for(i=0;i<str1.Length;i++)
{
int j=i-1;
output+= str1[i].ToString();
if(j>=0 && j<str2.Length)
output+=str2[j].ToString();
}
Console.WriteLine(output);



Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.Net on: 3/6/2012 [Member] Starter | Points: 25

Up
0
Down
hi Hmanjarawala sir i get following error sir

System.Char[]System.Char[]FSystem.Char[]USystem.Char[]NSystem.Char[]DSystem.Char
[]A


gowthaman8870226416

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 3/8/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
If you use Himanshu Manjarawala Code.You will get this answer:
Output:
doFtUnNeDtA

But you use my Code:
      

char[] str1 = "dotnet".ToCharArray();

char[] str2 = "FUNDA".ToCharArray();



string output = "";



for (int k = 0; k < str1.Length; k++)
{

int j = k - 1;
if (k == 0)
{
output += str1[k].ToString();
}
else if (k > 0)
{
if (j >= 0 && j < str2.Length)
output += str2[j].ToString();
output += str1[k].ToString();
}
//if (j >= 0 && j < str2.Length)
// output += str2[j].ToString();
}
MessageBox.Show(output);


Output:
dFoUtNnDeAt

Check and Mark.

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response