net字符串的处理.ppt

  1. 1、本文档共27页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
net字符串的处理.ppt

字符串的处理 字符串的处理 在 C# 中有直接表示字符串的类型,即string 类型,它是 char 字符的集合,就像是 char 类型的只读数组。 .NET Framework 支持对字符串进行强大的处理功能,如字符串的查找、替换、格式化、调整等。 字符串的处理 遍历字符串 可以像遍历一维数组一样遍历字符串: 由于字符是只读的,不能对单个字符进行修改: 字符串的处理 与数组类似,可通过 字符串.Length 获取字符串长度: 字符串的处理 可以和数组一样使用 foreach 语句对字符串进行遍历: * 字符串的拼接 可以使用‘+’号来连接两个字符串: 字符串的处理 连接结果 = 字符串1 + 字符串2; string firstName = “Martin”; string lastName = “Robert”; string name = lastName + “ “ + firstName; Console.WriteLine(name); Robert Martin string theString = “Hello World!”; char theChar = theString[ 0 ]; string theString = “Hello World!”; //! theString[ 0 ] = ‘h’; string theString = “Hello World!”; for (int i=0; itheString.Length; i++) { Console.Write(theString[i]); } Console.WriteLine(); string theString = “Hello World!”; foreach (char theChar in theString) { Console.Write(theChar); } Console.WriteLine(); 可通过 字符串.ToCharArray() 的形式来获得表示字符串的字符数组,以便修改: string theString = “Hello World!”; char[] theChars = theString.ToCharArray(); for (int i=0; i theChars.Length; i++) { Console.Write(theChars[i]); } Console.WriteLine(); 字符串的处理 字符串转换 全部转换成大写 string theString = “Hello World!”; string upperString = theString.ToUpper(); Console.WriteLine(theString); Console.WriteLine(upperString); 字符串的处理 Hello World! HELLO WORLD! 字符串转换 全部转换成小写 string theString = “Hello World!”; string lowerString = theString.ToLower(); Console.WriteLine(theString); Console.WriteLine(lowerString); 字符串的处理 Hello World! hello world! 字符串转换 使用字符串转换来忽略大小写 Console.Write(“User name: “); string username = Console.ReadLine(); Console.Write(“Password: “); string password = Console.ReadLine(); if (username.ToLower() == “somebody” password == “test”) Console.WriteLine(“Welcome!”); else Console.WriteLine(“Invalid username or password!”); 字符串的处理 字符串转换 使用 字符串.Trim() 来调整字符串,使之去除掉左右空格。 string theString = “ Hello world! ”; string trimString = theString.Trim(); Console.WriteLine(“|”+theString+”|”); Console.WriteLine(“|”

文档评论(0)

rewfdgd + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档