python字符串操作,以及对应的C#实现
--IndexOf--
python:
inx = str.find("aa")
c#:
var inx = str.IndexOf("aa");
--LastIndexOf--
python
inx = str.rfind("aa")
c#
var inx = str.LastIndexOf("aa");
--Remove--
python
str = "asdfg"
str = str[3:]
#fg
c#
var str = "asdfg";
str = str.Remove(, );
//fg
--反向Remove--
python
str = "asdfg"
str = str[:-2]
#asd
c#
var str = "asdfg";
str = str.Remove(str.Length-, );
//asd
--SubString取中间段--
python
前后均为索引
str = "asdfg"
str = str[1:3]
#sd
c#
var str = "asdfg";
str = str.Substring(1, 2);
//sd
--TrimStart, TrimEnd--
python
def main():
print "qwe_xxxxx".lstrip("qwe_") #Output:xxxxx #lstrip对应TrimStart
#rstrip对应TrimEnd
#strip为统一删除
#如果不填写参数,默认删除/r/n这类符号
C#
var str = "qwe_xxxxx";
str = str.TrimStart("qwe_")
//Output:xxxxx
python字符串操作,以及对应的C#实现的更多相关文章
- Python 字符串操作
Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...
- python字符串操作实方法大合集
python字符串操作实方法大合集,包括了几乎所有常用的python字符串操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下: #1.去空格及特殊符号 s.st ...
- 转 Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
转自: http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html 黄聪:Python 字符串操作(string替换.删除.截取. ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- python字符串操作总结
python中有各种字符串操作,一开始python有个专门的string模块,要使用需先import string.后来从python2.0开始,string方法改用str.method()形式调用, ...
- 『无为则无心』Python序列 — 17、Python字符串操作常用API
目录 1.字符串的查找 @1.find()方法 @2.index()方法 @3.rfind()和rindex()方法 @4.count()方法 2.字符串的修改 @1.replace()方法 @2.s ...
- python 字符串操作。。
#字符串操作 以0开始,有负下标的使用0第一个元素,-1最后一个元素,-len第一个元 素,len-1最后一个元素 name= "qwe , erw, qwe "print(nam ...
- Python 字符串操作,截取,长度
1.字符串操作: 字符串长度: s = "; slen = len(s); 字符串截取: print s[:-:-] #截取,逆序隔1个取一个字符 print s[:-:-] #截取,逆序隔 ...
- python字符串操作、文件操作,英文词频统计预处理
1.字符串操作: 解析身份证号:生日.性别.出生地等. 凯撒密码编码与解码 网址观察与批量生成 解析身份证号:生日.性别.出生地等 def function3(): print('请输入身份证号') ...
- python字符串操作2
在python有各种各样的string操作函数.在历史上string类在python中经历了一段轮回的历史.在最开始的时候,python有一个专 门的string的module,要使用string的方 ...
随机推荐
- 基于tiny4412的Linux内核移植 -- eMMC驱动移植(六)
作者信息 作者: 彭东林 邮箱:pengdonglin137@163.com QQ:405728433 平台简介 开发板:tiny4412ADK + S700 + 4GB Flash 要移植的内核版本 ...
- [转]解决Eclipse更新ADT插件时遇到的Eclipse reports rendering library more recent than ADT plug-in问题
使用 SDK Manager 工具更新下载新版本后,无法显示可视化布局,同时提示 This version of the rendering library is more recent than y ...
- 四、logback日志
加入在main\resources 创建logback.xml文件 <configuration> <!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, ...
- 事务内执行sql修复的简易模板
-- ============================================= -- Script Template -- ============================= ...
- Intellij IDEA中使用log4j日志
一.在pom.xml中添加依赖 <dependency> <groupId>log4j</groupId> <artifactId>log4j</ ...
- hdu1227 Fast Food
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1227 #include <iostream> #include <cstdio&g ...
- 【JavaScript】ReactJS基础
初探React,将我们的View标签化 前言 我之前喜欢玩一款游戏:全民飞机大战,而且有点痴迷其中,如果你想站在游戏的第一阶梯,便需要不断的练技术练装备,但是腾讯的游戏一般而言是有点恶心的,他会不断的 ...
- 使用git-svn迁移SVN至GitLab
使用git-svn迁移SVN至GitLab 1.安装git和git-svn 后面的步骤中对git版本有一定要求,通过yum安装的git版本较低,这里进行编译安装 [root@DevTest ~]# y ...
- apache无法启动:The request operation has failed
apache无法启动提示the requested operation has failed 的错误信息,有以下几种解决方法:1.80端口占用 apache默认使用的端口是80,而IIS和迅雷用的也是 ...
- Maven 多套环境配置
在Java开发中会配置不同环境,可通过Maven的profile指定不同的环境配置,pom.xml配置如下: <project xmlns="http://maven.apache.o ...