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. JDBC连接各种数据库的方法(经典)

    1)连接Oracle 8/8i/9i/10g/11g(thin模式) Class.forName("oracle.JDBC.driver.OracleDriver").newIns ...

  2. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  3. INDY idhttp Post用法

    http://www.cnblogs.com/tk-del/archive/2013/05/10/3071541.html function Post(AURL: string; ASource: T ...

  4. STM32F103定时器输出PWM波控制直流电机

    这个暑假没有回家,在学校准备九月份的电子设计竞赛.今天想给大家分享一下STM32高级定时器输出PWM波驱动直流电机的问题.. 要想用定时器输出的PWM控制直流电机,,首先要理解“通道”的概念..一个定 ...

  5. hdu1498 50 years, 50 colors --- 最小点覆盖

    给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...

  6. Android-Volley详解

    一.Volley简介和特点 1. 简介: 并发.效率.性能 高要求 Volley(齐射,迸发) Volley是Google2013发布的Android平台上的网络通信库 2. Volley特点: 通信 ...

  7. js 处理url中文参数 java端接收处理

    正常情况下当http请求中带有中文参数时,浏览器会自动对中文进行一次编码(按照当前页面的pageEncoding),java端容器会对接收到的参数自动进行一次转码,则request.getParame ...

  8. [转]使用 PIVOT 和 UNPIVOT

    可以使用 PIVOT 和 UNPIVOT 关系运算符将表值表达式更改为另一个表.PIVOT 通过将表达式某一列中的唯一值转换为输出中的多个列来旋转表值表达式,并在必要时对最终输出中所需的任何其余列值执 ...

  9. mysql主从复制 主从配置(windows系统上)

    OS:Windows7 DB:MYSQL5.6.2 1.正常安装第一个mysql(安装步骤省略)  2.在控制面板里停止第一个mysql服务  3.将C:\Program Files\MySQL目录下 ...

  10. git fetch和git pull之间的区别--转载

    原文地址:http://blog.csdn.net/a19881029/article/details/42245955 git fetch和git pull都可以用来更新本地库,它们之间有什么区别呢 ...