这篇blog主要是总结我们在平常开发过程中对字符串的一些操作:

#字母大小写转换
#首字母转大写
#去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串连接起来
#去除'hello_for_our_world'中的'_',并且把从第一个'_'以后的单词首字母大写

具体的代码demo:

 1 #字母大小写转换
 2 #首字母转大写
 3 #去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串连接起来
 4 #去除'hello_for_our_world'中的'_',并且把从第一个'_'以后的单词首字母大写
 5 low_strs = 'abcd'
 6 uper_strs = 'DEFG'
 7 test_strA = 'hello_world'
 8 test_strB = 'goodBoy'
 9 test_strC = 'hello_for_our_world'
10 test_strD = 'hello__our_world_'
11
12 #小写转大写
13 low_strs = low_strs.upper()
14 print('abcd小写转大写:', low_strs)
15
16 #大写转小写
17 uper_strs = uper_strs.lower()
18 print('DEFG大写转小写:', uper_strs)
19
20 #只大写第一个字母
21 test_strB = test_strB[0].upper() + test_strB[1:]
22 print('goodBoy只大写第一个字母:', test_strB)
23
24 #去掉中间的'_',其他符号都是可以的,如:'.',',',';'
25 test_strA = ''.join(test_strA.split('_'))
26 print('hello_world去掉中间的\'_\':', test_strA)
27
28 #去除'hello_for_our_world'中的'_',并且把从第一个'_'以后的单词首字母大写
29 def get_str(oriStr,splitStr):
30     str_list = oriStr.split(splitStr)
31     if len(str_list) > 1:
32         for index in range(1, len(str_list)):
33             if str_list[index] != '':
34                 str_list[index] = str_list[index][0].upper() + str_list[index][1:]
35             else:
36                 continue
37         return ''.join(str_list)
38     else:
39         return oriStr
40
41 print('去除\'hello_for_our_world\'中的\'_\',并且把从第一个\'_\'以后的单词首字母大写:', get_str(test_strC,'_'))
42 print('去除\'hello__our_world_\'中的\'_\',并且把从第一个\'_\'以后的单词首字母大写:', get_str(test_strD,'_'))

运行效果:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
abcd小写转大写: ABCD
DEFG大写转小写: defg
goodBoy只大写第一个字母: GoodBoy
hello_world去掉中间的'_': helloworld
去除'hello_for_our_world'中的'_',并且把从第一个'_'以后的单词首字母大写: helloForOurWorld
去除'hello__our_world_'中的'_',并且把从第一个'_'以后的单词首字母大写: helloOurWorld
>>> 

python开发_大小写转换,首字母大写,去除特殊字符的更多相关文章

  1. python字符串的操作(去掉空格strip(),切片,查找,连接join(),分割split(),转换首字母大写, 转换字母大小写...)

    #可变变量:list, 字典#不可变变量:元祖,字符串字符串的操作(去掉空格, 切片, 查找, 连接, 分割, 转换首字母大写, 转换字母大小写, 判断是否是数字字母, 成员运算符(in / not ...

  2. python title() upper() lower() 以首字母大写的方式显示每个单词/将字符串改为全部大写或全部小写

    以首字母大写的方式显示每个单词 [root@chenbj python]# cat name.py #!/usr/bin/env python # _*_ coding:utf-8 _*_ name ...

  3. Python 2:str.title()(使字符串每个单词首字母大写)

    name = "hello,world! hello,python!" print(name.title()) #单词首字母大写 运行结果将会是:Hello,World!Hello ...

  4. Python - 首字母大写(capwords) 和 创建转换表(maketrans) 具体解释

    首字母大写(capwords) 和 创建转换表(maketrans) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/27 ...

  5. 012.Oracle数据库,字符串文本大小写转换,转大写,转小写,首字母大写

    /*转大写*/ SELECT UPPER(TITLE_EN) FROM ME_EO WHERE ( ISSUE_DATE BETWEEN to_date( '2017-02-04', 'yyyy-MM ...

  6. 【Python实践-6】将不规范的英文名字,变为首字母大写,其他小写的规范名字

    #利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字. def f1(s): s=s.capitalize() return s list1= ['adam', 'L ...

  7. Python实现将不规范的英文名字首字母大写

    Python实现将不规范的英文名字首字母大写 这篇文章给大家主要介绍的是利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.文中给出了三种解决方法,大家可以根据需要选 ...

  8. CSS通过text-transform实现大写、小写和首字母大写转换

    再日常项目中可能会用到一些特殊的样式,比如大写字母转小写.小写字母转大写.首字母大写等. 可以通过 CSS 的 text-transform 属性来实现: text-transform 转换不同的文本 ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:设定单词首字母大写

    <!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...

随机推荐

  1. Java并发编程:Thread类的使用介绍

    在学习Thread类之前,先介绍与线程相关知识:线程的几种状态.上下文切换,然后接着介绍Thread类中的方法的具体使用. 以下是本文的目录大纲: 一.线程的状态 二.上下文切换 三.Thread类中 ...

  2. Nio Client

    public class NIOClient { static int SIZE = 2; final static int bufferSize = 500 * 1024; static InetS ...

  3. malloc 申请得到的内存后,再 free 释放它的时候,操作系统会立即收回那块内存吗?

    stackoverflow上的回答: In many malloc/free implementations, free does normally not return the memory to  ...

  4. realloc,c语言

    realloc #include <stdlib.h> main() { char* ptr=NULL; char* ptr2=NULL; ptr = malloc(); printf(& ...

  5. window.external.JavaScriptCallCpp

    方案2: 1.编写html <html> <head> </head> <body> <script language="javascr ...

  6. BZOJ 1297: [SCOI2009]迷路( dp + 矩阵快速幂 )

    递推式很明显...但是要做矩阵乘法就得拆点..我一开始很脑残地对于每一条权值v>1的边都新建v-1个节点去转移...然后就TLE了...把每个点拆成9个就可以了...时间复杂度O((9N)^3* ...

  7. rsyslog 传输日志

    nginx 服务器: front-end:/usr/local/nginx/logs# cat /etc/rsyslog.conf | grep -v "^$" | grep -v ...

  8. 使用自定义脚本扩展程序自动执行 VM 自定义任务

     在 Build 开发者大会上推出VM 扩展程序的其中一个称为"自定义脚本扩展程序",它支持 PowerShell.如果这是您第一次访问这些博客,可能需要查看以前的博客,请单击 ...

  9. DAL – RDBMS 的分区

    编辑人员注释:本文章由AzureCAT 云与企业工程组的高级项目经理Shaun Tinline-Jones 和Chris Clayton 共同撰写. "云服务基础"应用程序也称作& ...

  10. ANDROID自己定义视图——onLayout源代码 流程 思路具体解释

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 简单介绍: 在自己定义view的时候.事实上非常easy.仅仅须要知道3步骤: 1.測量- ...