.string的Split方法的使用

这个例子就是通过制定的符号来将词组分开,Splite(分割的字符,分割的份数)

using System;
using System.Collections; public class Test
{
public static void Main()
{
string data = "Mike,McMillan,3000 W. Scenic,North Little Rock,AR,72118";
string[] sdata;
char[] delimiter=new char[]{','};
sdata = data.Split(delimiter,);
foreach (string val in sdata)
{
Console.WriteLine(val);
}
}
} .string的Join用法,使用指定的连接符来对字符数组进行连接
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string [] sdata=new string[]{"i","want","to","do","it"};
string data;
data=String.Join(" ", sdata);
Console.WriteLine(data); }
} .string的其他方法:
Euqal:用于比较两个字符串的大小,如果相等就返回True,如果不相等就放回false; Compare To:比较两个字符串的大小,如果根据大小返回-,,; .StartsWith和EndsWith的用法
这个函数用来判断字符当中是否是以指定字符开始或者结束的
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string []strs=new string[]{"dogs","cats","mat","apples","banana"};
foreach (string val in strs)
{
if(val.EndsWith("s"))
Console.WriteLine(val);
if(val.StartsWith("a"))
Console.WriteLine("**"+val);
} }
} .字符的插入Insert,Remove
可以在指定位置插入一个字符,并返回处理过的字符串
Remove可以在指定位置删除指定长度的字符
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string str = "你好,今天真好";
str = str.Insert(, "啊");
Console.WriteLine(str);
str = str.Remove(, );
Console.WriteLine(str);
}
} .Replace方法
该方法是用于替换字符串中的字符
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string str = "你好啊,我已经完成了";
str = str.Replace("好", "不");
Console.WriteLine(str); }
} .文本对齐方式
using System;
using System.Collections;
using System.Linq;
public class Test
{
public static void Main()
{
string s1 = "hello";
string s2 = "world";
string s3 = "goodbyte";
Console.WriteLine(s1.PadLeft(10)); //用于左对齐(空格补齐左对齐)
Console.WriteLine(s2.PadRight(10)); //用于右对齐
}
} .字符串的大小写转换
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string s1 = "hello";
s1 = s1.ToUpper(); //转化成大写字符
Console.WriteLine(s1); string s2 = "HelL0"; //转换成小写
s2 = s2.ToLower();
Console.WriteLine(s2); }
} .去掉字符串中头部或则尾部的一些其他指定字符,Trim名为修剪,就是修饰用的
该方法只能去掉字符串的头部或则尾部中间的部分不能去掉
using System;
using System.Collections;
using System.Linq; public class Test
{
public static void Main()
{
string[] htmlComments = new string[]
{
"<!-- Start Page !!Number Function -->",
"<!-- Get user name and password-->",
"<!-- End Title page -->",
"<!-- End script -->"
}; char[] commentChars=new char[]{'<','!','-','>'};
for (int i = ; i <=htmlComments.GetUpperBound(); i++)
{
htmlComments[i] = htmlComments[i].Trim(commentChars); //将两端都去掉
//htmlComments[i] = htmlComments[i].TrimEnd(commentChars); //去掉尾部
//htmlComments[i] = htmlComments[i].TrimStart(commentChars); //去掉头部
}
for (int i = ; i <= htmlComments.GetUpperBound(); i++)
{
Console.WriteLine(htmlComments[i]);
} }
}

最新文章

  1. Self-Host Web API 学习笔记
  2. 常见的sql语句 注意点及用法【区分mysql 和Sqlserver】
  3. MVC+EF 自定义唯一性验证
  4. jQuery form插件的使用--用 formData 参数校验表单,验证后提交(简单验证).
  5. linux实践——简单程序破解
  6. android 拍照,裁切,上传圆形头像, 图片等比缩放
  7. 年薪10W和100w的人差距在哪?
  8. Android的UI两大基石
  9. js方法中的this
  10. TestThreadPoolExecutor.java
  11. apicloud ios 打包流程
  12. 【学习总结】GirlsInAI ML-diary day-10-if条件执行
  13. Pi的计算
  14. Flash芯片你都认识吗?
  15. vue 打开新页面
  16. Linux 文本编辑器 vim
  17. resharper安装后,F12不能转到定义,也不是反编译,而是转到对象浏览器(object browser)
  18. 【Html 学习笔记】第四节——框架
  19. C#的datatable使用
  20. APP测试点集合

热门文章

  1. 玩转ubuntu之初体验
  2. (二)校园信息通微信小程序从后台获取首页的数据笔记
  3. MongoDB学习笔记(转)
  4. Coverity代码扫描工具
  5. Intellij Idea调试java文件时 怎么跳过class文件?
  6. ThinkPHP5配置redis缓存
  7. Python学习(三十六)—— Cookie、Session和自定义分页
  8. LNMP一键安装包添加虚拟主机、删除虚拟主机及如何使用伪静态
  9. 使用BITSADMIN下载文件
  10. aspnet core运行后台任务