-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToWeirdCase.cs
47 lines (44 loc) · 1.32 KB
/
ToWeirdCase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeWarsSolutions
{
public class ToWeirdCase
{
public static string ChangeToWeirdCase(string s)
{
var words = s.Split(' ');
var Myoutput = new List<string>();
foreach (string word in words)
{
var letters = word.ToArray();
for (int i = 0; i < letters.Length; i++)
{
if (i % 2 == 0)
{
if (i == 0) letters[i] = char.ToUpper(letters[i]); // make first letter capital
else letters[i] = char.ToUpper(letters[i]);
}
else
{
letters[i] = char.ToLower(letters[i]);
}
}
Myoutput.Add(new string(letters));
}
return string.Join(" ", Myoutput);
}
/*
public static string ToWeirdCase(string s)
{
return string.Join(" ",
s.Split(' ')
.Select(w => string.Concat(
w.Select((ch, i) => i % 2 == 0 ? char.ToUpper(ch) : char.ToLower(ch)
))));
}
*/
}
}