Case swapping
Case swapping
Description:
Given a string, swap the case for each of the letters.
e.g. CodEwArs --> cODeWaRS
Examples
Kata.Swap("") == ""
Kata.Swap("CodeWars") == "cODEwARS"
Kata.Swap("abc") == "ABC"
Kata.Swap("ABC") == "abc"
Kata.Swap("123235") == "123235"
using System;
using System.Linq; public static class Kata
{
public static string Swap(string str)
{
return string.Join(string.Empty, str.Select(character => char.IsLower(character) ? char.ToUpper(character) : char.IsUpper(character) ? char.ToLower(character) : character));
} //public static string Swap(string str)
//{
// str = string.Join(string.Empty, str.Select(Selector));
// return str; //your code here
//} //public static char Selector(char character)
//{
// char tempCharacter = character;
// if (char.IsLower(character))
// {
// tempCharacter = char.ToUpper(character);
// }
// else if (char.IsUpper(character))
// {
// tempCharacter = char.ToLower(character);
// }
// return tempCharacter;
//}
}
其他人的解法
需要学习的是:char.ToUpper以及char.ToLower本身可以处理非大小写的字符,不需要另外多一个判断
using System;
using System.Linq; public static class Kata {
public static string Swap(string str) {
return String.Concat(str.Select(c => Char.IsUpper(c) ? Char.ToLower(c) : Char.ToUpper(c)));
}
}
Case swapping的更多相关文章
- Swapping
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Referring back to Fig ...
- [POJ 1674] Sorting by Swapping
Sorting by Swapping Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9514 Accepted: 50 ...
- Matrix Swapping II(求矩阵最大面积,dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 第15届浙江省赛 D Sequence Swapping(dp)
Sequence Swapping Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a strange s ...
- HDU 2830 Matrix Swapping II (预处理的线性dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- File System Design Case Studies
SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Int ...
- D:Sequence Swapping
BaoBao has just found a strange sequence {<, >, <, >, , <, >} of length in his poc ...
- C#中,switch case语句中多个值匹配一个代码块的写法
switch (num) { case 1: Response.Write("1"); break; case 2: case 3: Response.Write("2| ...
- Android Studio快捷键switch case 轻松转换为if else
Android Studio快捷键switch case 轻松转换为if else 今天碰到的问题,没有找到资料,后面找到了方法,这个记下来,转载请注明出处:http://www.cnblogs.co ...
随机推荐
- MySQL的记录长度
MySQL的记录长度 MySQL默认规定一条记录最大的长度是65535字节,所有的字段加在一起所占的字节数不能超过65535.但是MySQL中字段的长度有的时使用字节来规定int,有些字段类型是使用字 ...
- 粵語/廣東話/Cantonese 資料/Material
一.粵語歌詞網 1.海闊天空(粵語) 歌詞 今天我 寒夜裡看雪飄過 gam1 tin1 ngo5 hon4 je6 leoi5 hon3 syut3 piu1 gwo3 懷著冷卻了的心窩漂遠方 waa ...
- OpenJudge 2737 大整数除法
链接地址:http://bailian.openjudge.cn/practice/2737/ 题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 求2个大的正整数相除的商 输入 第 ...
- spring常用的连接池属性文件配置
(一) DBCP 引入jar文件 commons-dbcp-1.2.1.jar commons-pool-1.3.jar二个包. spring配置文件 <bean id="dataSo ...
- Java 使用反射拷贝对象一般字段值
在<Java解惑>上面看到第八十三例--诵读困难者,要求使用非反射实现单例对象的拷贝.查阅了部分资料,先实现通过反射拷贝对象. 1. 编写需要被拷贝的对象Person package co ...
- C++ const修饰函数、函数参数、函数返回值
const修饰函数 在类中将成员函数修饰为const表明在该函数体内,不能修改对象的数据成员而且不能调用非const函数.为什么不能调用非const函数?因为非const函数可能修改数据成员,cons ...
- JavaScript的事件监听、捕获和冒泡
在前端开发中,我们经常需要对某些事件进行监听.这样只要在指定的元素上触发了该事件,就会执行一个回调函数来进行相关的操作. 而JavaScript中事件监听的方法总共有三种,分别如下: element. ...
- MVC-简单验证码制作
1.制作验证码: using System; using System.Collections.Generic; using System.Drawing; using System.Drawing. ...
- linux下修改IP信息
在Linux的系统下如何才能修改IP信息 以前总是用ifconfig修改,重启后总是得重做.如果修改配置文件,就不用那么麻烦了- A.修改ip地址 即时生效: # ifconfig eth0 192. ...
- 原生javascript效果:无缝滚动
<style type="text/css"> #con {width:400px; padding:10px; margin:20px auto; text-alig ...