Code
convertToAltCaps("hello") returns "hElLo" convertToAltCapsCode
("section is awesome") returns "sEcTiOn Is AwEsOmE"Code
my program does not work when enter more than 4 lettersCode
Pls Help MeCode
using System;Code
using System.Collections.Generic;Code
using System.Linq; using System.Text;Code
using System.Threading.Tasks;Code
namespace AltCap {Code
class Program {Code
static void Main(string[] args) {Code
Console.WriteLine("Enter Your String: ");Code
string s = Console.ReadLine();Code
StringBuilder b = new StringBuilder(s);Code
for(int i = 1; ib.Length;i+=2) {Code
char c = Char.ToUpper(b[i]);Code
b.Replace(b[i], c); }Code
Console.WriteLine(b);Code
Console.ReadKey(); } }
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted May 3, 2014, 10:12 PM EDT
VulpesRank #55 · 29.2K reputationPosted May 4, 2014, 1:15 AM EDT
Try this:
Mukesh NayakRank #1,172 · 1.5K reputationPosted May 4, 2014, 1:15 AM EDT
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,
VulpesRank #55 · 29.2K reputationPosted May 4, 2014, 1:22 AM EDT
sEcTiOn Is AwEsOmE
rather than
sEcTiOn iS AwEsOmE
Mukesh NayakRank #1,172 · 1.5K reputationPosted May 4, 2014, 1:48 AM EDT
Bhupinder Rajput2 reputationPosted Jan 29, 2015, 11:26 PM EST
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;
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts