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. PostgreSQL的注释嵌套的例子

    pgsql=# -- Multiline comments pgsql=# SELECT 'Multi' /* This comment extends across pgsql*# * number ...

  2. Java常见排序算法之直接插入排序

    在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...

  3. Java面试试题

    第一,谈谈final, finally, finalize的区别.最常被问到. 第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以impl ...

  4. Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本号的开发环境

    写这篇博客时2D游戏引擎Cocos2d-x的最新版本号为2.1.4,记得非常久曾经使用博客园博主子龙山人的一篇博文<Cocos2d-x win7+vs2010配置图文具体解释(亲測)>成功 ...

  5. BackTrack5 (BT5)无线password破解教程之WPA/WPA2-PSK型无线password破解

    昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...

  6. Android图片圆角效果

    一般来说图片加圆角可以使用 Java 的方式来进行, 对图片略加处理即可, 但也可以使用纯XML+Nice-Patch图片来进行, 这样的速度会更快. 如果背景是纯色的情况下建议使用此方法. 原理则是 ...

  7. QoS 测量 (目标,方法,协议)

    本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...

  8. UVA11038- How Many O&#39;s?(组合数学)

    题目链接 题意:求出在a到b之间的数中,有多少个0. 思路:组合数学问题.能够枚举每一个位置上的数i,如果i之前的数为left,后面的为right,后面有num位数.当i != 0时,将i置为0,所以 ...

  9. 虚拟文件系统VFS

    Linux的文件系统是由虚拟文件系统作为媒介搭建起来的,虚拟文件系统VFS(Virtual File System)是Linux内核层实现的一种架构,为用户空间提供统一的文件操作接口.它在内核内部为不 ...

  10. 检测MYSQL不同步发邮件通知的脚本

    脚本代码如下:#!/bin/bash                                                                                   ...