1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using System.Threading.Tasks;
   6:   
   7:  namespace FunWithStrings
   8:  {
   9:      class Program
  10:      {
  11:          //基本操作
  12:          static void BasicStringFunctionality()
  13:          {
  14:              Console.WriteLine("Basic String Functionality:");
  15:              string str = "VisualStudio2013";
  16:              Console.WriteLine("Value of str:{0}", str);
  17:              Console.WriteLine("str has {0} characters.", str.Length); //获取长度
  18:              Console.WriteLine("str in uppercase:{0}", str.ToUpper()); //转成大写
  19:              Console.WriteLine("str in lowercase:{0}", str.ToLower()); //转成小写
  20:              Console.WriteLine("str contains the letter 2013 ? :{0}", str.Contains("2013")); //判断是否包含"2013"
  21:              Console.WriteLine("str after replace : {0}",str.Replace("2013","")); //将2013 替换掉
  22:              Console.ReadKey();
  23:          }
  24:          //拼接字符串
  25:          static void StringConcatenation()
  26:          {
  27:              //使用“+”拼接字符串
  28:              Console.WriteLine("String concatenation:");
  29:              string str1 = "字符串";
  30:              string str2 = "拼接";
  31:              string str3 = str1 + str2;
  32:              Console.WriteLine(str3);
  33:              Console.ReadKey();
  34:              //使用String.Concat()拼接
  35:              Console.WriteLine("String concatenation:");
  36:              string str4 = "世界杯";
  37:              string str5 = "比赛";
  38:              string str6 = String.Concat(str4, str5);
  39:              Console.WriteLine(str6);
  40:              Console.ReadKey();
  41:               
  42:          }
  43:          //给字符串转义
  44:          static void EscapeChars()
  45:          {
  46:              Console.WriteLine("Escape character:\a");
  47:              string stringWithTabs = "this\tis\ta\tdemo\t!";
  48:              Console.WriteLine(stringWithTabs);
  49:              Console.WriteLine("\"Hello Wolrd!\"");
  50:              Console.WriteLine("C:\\Windows\\System32\\drivers\\etc");
  51:              //使用逐字字符串
  52:              Console.WriteLine(@"D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7");
  53:              //使用逐字字符串保留空格
  54:              string longString = @"
  55:                                  春江潮水连海平,海上明月共潮生。
  56:                                  滟滟随波千万里,何处春江无月明! 
  57:                                  江流宛转绕芳甸,月照花林皆似霰; 
  58:                                  空里流霜不觉飞,汀上白沙看不见。 
  59:                                  江天一色无纤尘,皎皎空中孤月轮。 
  60:                                  江畔何人初见月?江月何年初照人? 
  61:                                  人生代代无穷已,江月年年只相似。";
  62:              Console.WriteLine(longString);
  63:              Console.ReadKey();
  64:          }
  65:          //相等性测试
  66:          static void StringWquality()
  67:          {
  68:              Console.WriteLine("字符串相等测试");
  69:              string str1 = "Hello";
  70:              string str2 = "World";
  71:              Console.WriteLine("str1={0}", str1);
  72:              Console.WriteLine("str2={0}", str2);
  73:              Console.WriteLine("str1=str2:{0}", str1 = str2);
  74:              Console.WriteLine("str1=Hello:{0}", str1 == "Hello");
  75:              Console.WriteLine("str1=HELLO:{0}", str1 == "HELLO");
  76:              Console.WriteLine("str1.Equals(str2):{0}", str1.Equals(str2));
  77:              Console.WriteLine("Hello.Equals(str2):{0}", "Hello".Equals(str2));
  78:              Console.ReadKey();
  79:          }
  80:          static void Main(string[] args)
  81:          {
  82:              BasicStringFunctionality();
  83:              StringConcatenation();
  84:              EscapeChars();
  85:              StringWquality();
  86:          }
  87:      }
  88:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

运行效果

C#_字符串的操作的更多相关文章

  1. Python 字符串大小写操作

    #coding=utf-8 #python中字符串的操作 # 字符串的大小写 s='hello_wOrld_oF_you' upper_str = s.upper() print('全部大写: ',u ...

  2. Python—字符串的操作

    字符串的操作 变量: 变量只能是 字母,数字或下划线的任意组合,但首个字符不能为数字,且不能有空格 以下关键字不能声明为变量: and ,as, assert, break ,class ,conti ...

  3. Python学习笔记:第3天 字符串的操作

    目录 1. python的数据类型 2. int类型的操作 3. bool类型 4. 字符串的操作 5. for循环 1. python的数据类型 int 整数 str 字符串.一般不会用字符串保存大 ...

  4. Python3 与 C# 面向对象之~继承与多态 Python3 与 C# 面向对象之~封装 Python3 与 NetCore 基础语法对比(Function专栏) [C#]C#时间日期操作 [C#]C#中字符串的操作 [ASP.NET]NTKO插件使用常见问题 我对C#的认知。

    Python3 与 C# 面向对象之-继承与多态   文章汇总:https://www.cnblogs.com/dotnetcrazy/p/9160514.html 目录: 2.继承 ¶ 2.1.单继 ...

  5. C#中字符串的操作大全

    一.C#中字符串的建立过程 例如定义变量 strT="Welcome to "; strT+="www.cuit.edu.cn"; 程序首先创建一个System ...

  6. ca78a_c++_字符串流在内存中的输入输出(速度快)

    /*ca78a_c++_字符串流在内存中的输入输出**字符串流:在内存中的输入输出.(在内存中进行,速度快)**文件流 :是对文件进行输入和输出.(在磁盘里面进行)istringstream(输入), ...

  7. Javascript-常用字符串数组操作

    字符串的操作在编写Js的过程中是不可避免的 因为它太多的API 还有相似的API让我们很头痛 为了避免以后遇到模拟两可的问题 还是做个笔记比较好 把常用的字符串操作记录下来成笔记 方便以后查找 No1 ...

  8. JavaScript 字符串常用操作

    JavaScript 字符串用于存储和处理文本.因此在编写 JS 代码之时她总如影随形,在你处理用户的输入数据的时候,在读取或设置 DOM 对象的属性时,在操作 Cookie 时,在转换各种不同 Da ...

  9. Python 基礎 - 字符串常用操作

    字符串常用操作 今天就介紹一下常用的字符串操作,都是以 Python3撰寫的 首字母變大寫 #!/usr/bin/env python3 # -*- coding:utf-8 -*- name = & ...

随机推荐

  1. android如何实现开机自动启动Service或app

    第一步:首先创建一个广播接收者,重构其抽象方法 onReceive(Context context, Intent intent),在其中启动你想要启动的Service或app. import and ...

  2. Keil AGDI Header File

    #ifndef __AGDI__INCED___ #define __AGDI__INCED___ //---Revision History: --------------------------- ...

  3. TL-WR703 USB不稳定/当前的总结

    http://see.sl088.com/wiki/WR703_USB%E4%B8%8D%E7%A8%B3%E5%AE%9A/%E5%BD%93%E5%89%8D%E7%9A%84%E6%80%BB% ...

  4. 给eclipse装一些插件

    最近换了一个环境,需要折腾一个新的eclipse配置,所以在这里记录下. 1.安装marketplace help=>install,输入地址:http://download.eclipse.o ...

  5. 【S17】使用“swap技巧”除去多余的容量

    1.考虑下面的需求,对于vec开始的时候有1000个元素,后来只有10个元素,那么vec的capacity至少还是1000,后面的990个内存单元,没有使用,但是还被vec霸占着.如何释放这些内存呢? ...

  6. C#生成软件注册码

    开发软件时,当用到商业用途时,注册码与激活码就显得很重要了.现在的软件破解技术实在在强了,各种国内外大型软件都有注册机制,但同时也不断地被破解.下面发的只是一个常用版本,发出源码被破就更容易了,但我们 ...

  7. Qt学习之自定义窗口部件

    自定义Qt窗口部件 实现一个十六进制的SpinBox,一般SpinBox只支持十进制整数,但是可以子类化方法实现该功能 需重新实现以下虚函数 virtual QString textFromValue ...

  8. SQL Server 2008数据库重命名方法

    假设SQL Server 2008中有个数据库test,现在要将其改名为zhy步骤:(1) 分离数据库:打开management studio,找到test数据库-->右键-->任务--& ...

  9. C++11 之for 新解

     前言     C++11这次的更新带来了令非常多C++程序猿期待已久的for range循环,每次看到javascript. lua里的for range.心想要是C++能有多好,心里别提多酸了.这 ...

  10. IIS6_IIS7日志文件位置

    准备统计下页面访问量 查找IIS日志,发现在以前IIS6日志的位置,竟然木有找到日志... 查看下IIS设置,发现IIS7和6的默认日志位置不一样额... IIS 6 Log files locati ...