Write a program in C# to convert every odd position words into uppercase using StringBuilder

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 486
The following function will do so

public string StrResult()
{
var strBuilder = new StringBuilder();

//input string
string input = "Hello! i am learning c#. It is a nice language to start with and also has multiple features.one among them in stringbuilder";

//split the string using space as a delimeter
var inputArray = input.Split(' ');

//find the length of the string
int stringLength = inputArray.Length;

Enumerable
.Range(0, stringLength)
.ToList()
.ForEach
(
i =>
{
if (i % 2 != 0) inputArray[i] = inputArray[i].ToUpper();
strBuilder.Append(' ' + inputArray[i]);
}
);
//return the value
return strBuilder.ToString();
}


Output
-------

 Hello! I am LEARNING c#. IT is A nice LANGUAGE to START with AND also HAS multiple FEATURES.ONE among THEM in STRINGBUILDER

Comments or Responses

Login to post response