how to convert String array to StringBuilder array or vice
versa?

Answers were Sorted based on User's Feedback



how to convert String array to StringBuilder array or vice versa?..

Answer / krishana singh gniit

using System;
using System.Text;

class Program
{
static void Main()
{
//
// Create an array with five strings.
//
string[] array = new string[5];
array[0] = "Dot";
array[1] = "Net";
array[2] = "Perls";
array[3] = "Sam";
array[4] = "Allen";

//
// Call the methods.
//
string result1 = ConvertStringArrayToString(array);
string result2 = ConvertStringArrayToStringJoin
(array);

//
// Display the results.
//
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.Read();
}

static string ConvertStringArrayToString(string[] array)
{
//
// Concatenate all the elements into a
StringBuilder.
//
StringBuilder builder = new StringBuilder();
foreach (string value in array)
{
builder.Append(value);
builder.Append('.');
}
return builder.ToString();
}

static string ConvertStringArrayToStringJoin(string[]
array)
{
//
// Use string Join to concatenate the string
elements.
//
string result = string.Join(".", array);
return result;
}
}

Is This Answer Correct ?    3 Yes 2 No

how to convert String array to StringBuilder array or vice versa?..

Answer / mohammed ameem

string [] strings = new string[]{"abcd","efgh","ijkl"}();
//create generic list of stringbuilder of length equal to
string array
List<System.Text.StringBuilder> stringBs = new
List<System.Text.StringBuilder>(strings.Length);
for(int i=0;i<strings.Length;i++)
{
stringBS[i] = new StringBuilder(s);//initialize
stringbuilder object
}
StringBuilder [] stringBuilders = stringBS.ToArray();

Is This Answer Correct ?    2 Yes 6 No

how to convert String array to StringBuilder array or vice versa?..

Answer / urukundappa.g

using System;
using System.Text;

class Program
{
static void Main()
{
// Create an array with five strings.
string[] array =
new string["Dot", "Net", "Perls", "Sam", "Allen"];

// Call the methods.
string result1 = ConvertStringArrayToString(array);
string result2 = ConvertStringArrayToStringJoin
(array);

// Display the results.
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.Read();
}

static string ConvertStringArrayToString(string[] array)
{
// Concatenate all the elements into a
StringBuilder.
StringBuilder builder = new StringBuilder();
foreach (string value in array)
{
builder.Append(value);
builder.Append('.');
}
return builder.ToString();
}

StringBuilder [] stringBuilders = builder.ToArray();

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C Sharp Interview Questions

What is the ouput of the following program?

0 Answers  


How do you pronounce c#?

0 Answers  


What is a console application in c#?

0 Answers  


How do you create dlls in .NET

0 Answers   Digital GlobalSoft,


how to Create a datagridview control with check box column with 8rows in it, the maximum number of check boxes checked should be 3, when user checks the 4th corresponding message should be displayed and check box should be checked. User can uncheck the checked boxes Note: read-only property should not be used

0 Answers   HCL, NIC,






Is c# or c++ better for games?

0 Answers  


What is uint64_t?

0 Answers  


Difference between ByVal and ByRef?

5 Answers   Microsoft,


What are the different approaches of passing parameters to a method?

0 Answers  


What is the default boolean value in c#?

0 Answers  


What is the difference between constant and readonly in c#?

0 Answers  


What is namespace in oop?

0 Answers  


Categories