string 类型的使用方法
2015-10-30 11:40
239 查看
string
a = "hello world!";
string
b = a.Substring(6); //获取下标为6以后的全部字符。
string
c = a.Substring(6, 2); //获取下标为6以后的2个字符。
Console.WriteLine(b);
Console.WriteLine(c);
string
d = a.Insert(0, "pkm "); //在下标为0之前插入"pkm
"
Console.WriteLine(d);
string
e = d.Insert(d.Length - 1, " good"); //在下标为长度减1(最后一个)前插入" good"
Console.WriteLine(e);
string
f = a.Remove(6); //删除下标从6开始的后面的全部字符
Console.WriteLine(f);
string
g = a.Remove(6, 2); //删除下标从6开始的后面的2个字符
Console.WriteLine(g);
string
h = a.Replace('!', '*'); //将!替换为
*
Console.WriteLine(h);
string
i = a.Replace("hello", "HELLO"); //将hello
替换成 HELLO
Console.WriteLine(i);
//转义字符@ 下面的 j==k
string
j = "C:\temp\temp1\temp2";
Console.WriteLine(j);
string
k = @"C:temptemp1temp2";
Console.WriteLine(k);
a = "hello world!";
string
b = a.Substring(6); //获取下标为6以后的全部字符。
string
c = a.Substring(6, 2); //获取下标为6以后的2个字符。
Console.WriteLine(b);
Console.WriteLine(c);
string
d = a.Insert(0, "pkm "); //在下标为0之前插入"pkm
"
Console.WriteLine(d);
string
e = d.Insert(d.Length - 1, " good"); //在下标为长度减1(最后一个)前插入" good"
Console.WriteLine(e);
string
f = a.Remove(6); //删除下标从6开始的后面的全部字符
Console.WriteLine(f);
string
g = a.Remove(6, 2); //删除下标从6开始的后面的2个字符
Console.WriteLine(g);
string
h = a.Replace('!', '*'); //将!替换为
*
Console.WriteLine(h);
string
i = a.Replace("hello", "HELLO"); //将hello
替换成 HELLO
Console.WriteLine(i);
//转义字符@ 下面的 j==k
string
j = "C:\temp\temp1\temp2";
Console.WriteLine(j);
string
k = @"C:temptemp1temp2";
Console.WriteLine(k);
相关文章推荐
- 版本控制
- LeetCode刷题
- Treap
- Xshell界面输出中文乱码现象解决方法
- SVProgressHUD
- 在Emacs中启用Fcitx输入法
- iis7 500错误日志报 LOG_FILE_MAX_SIZE_TRUNCATE
- Spring MVC篇一、搭建Spring MVC框架
- 数据库什么时候建立索引?
- 数据导出
- 记录一些数据库事物的头条问题
- JAVA中的访问权限
- 高斯模糊相关链接
- 斯坦福大学深度学习与自然语言处理课程解读
- Cocoapod安装 - 管理第三方库
- iOS开发项目自动生成技术文档
- Linux中,特殊宏 __bitwise、 __force、 __init 、__initdata 的使用
- OpenGL三角形几何变换
- VS2010调试 多进程
- 怎么学习编程