convertToAltCaps("hello") returns "hElLo" convertToAltCaps
("section is awesome") returns "sEcTiOn Is AwEsOmE"
my program does not work when enter more than 4 letters
Pls Help Me
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
using System.Threading.Tasks;
namespace AltCap {
class Program {
static void Main(string[] args) {
Console.WriteLine("Enter Your String: ");
string s = Console.ReadLine();
StringBuilder b = new StringBuilder(s);
for(int i = 1; i<b.Length;i+=2) {
char c = Char.ToUpper(b[i]);
b.Replace(b[i], c); }
Console.WriteLine(b);
Console.ReadKey(); } }
Bhupinder RajputPosted Jan 30, 2015, 4:26 AM
string ff = string.Empty;
for (int i = 0; i < tt.Length; i++)
{
if (i % 2 == 0)
{
ff = ff + tt[i].ToString().ToUpper();
}
else
{
ff = ff + tt[i].ToString().ToLower();
}
}
var result = ff;
Mukesh NayakPosted May 4, 2014, 5:48 AM
VulpesPosted May 4, 2014, 5:22 AM
sEcTiOn Is AwEsOmE
rather than
sEcTiOn iS AwEsOmE
Mukesh NayakPosted May 4, 2014, 5:15 AM
b.Replace(b[i], c)
you are trying to use replace with string builder and in turn it is doing a replace to all the characters in a particular string. We have replace the character considering the position of that character. We can replace that particular line by
or
which will get us the required result. And i don't think it has to do anything with number of words in the string.
Hope this will help,
VulpesPosted May 4, 2014, 5:15 AM
Try this:
Lakshmanan Sethu SankaranarayanPosted May 4, 2014, 2:12 AM