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. cocos2dx Http网络编程

    转自:http://blog.csdn.net/wangbin_jxust/article/details/9632771,http://blog.csdn.net/wangbin_jxust/art ...

  2. linux 下使rdate命令支持ipv6 ntp server 同步时间

    如果使用linux 下,busybox自带的rdate命令 去ipv6 的ntp server 同步时间的话,会提示invalid argument :无效参数. 那么现在下载rdate的源码并对其进 ...

  3. PhoneGap+jQuery Mobile+Rest 访问远程数据

    最近研究Mobile Web技术.发现了一个好东西-PhoneGap! 发现用PhoneGap+jQuery Mobile是一个很完美的组合! 本实例通俗易懂.适合广大开发人群:高富帅.白富美.矮穷戳 ...

  4. SSI框架中配置log4j

    事实上主要是log4j配置,跟SSI关系不大. web.xml中加入 <context-param> <param-name>log4jConfigLocation</p ...

  5. POJ 3159 Candies(SPFA+栈)差分约束

    题目链接:http://poj.org/problem?id=3159 题意:给出m给 x 与y的关系.当中y的糖数不能比x的多c个.即y-x <= c  最后求fly[n]最多能比so[1] ...

  6. xmf 翻译

    避免在详细信息视图的确认对话框显示? https://documentation.devexpress.com/#Xaf/CustomDocument3160 我如何获得从登录窗口应用程序的数据库? ...

  7. JS的加载方式---同步和异步

    同步加载及异步加载,只有这两种方式. 动态加载是异步加载的方式之一. ajax加载也是异步加载.

  8. iOS开发——数据持久化OC篇&plist文件增删改查操作

    Plist文件增删查改   主要操作: 1.//获得plist路径    -(NSString*)getPlistPath: 2.//判断沙盒中名为plistname的文件是否存在    -(BOOL ...

  9. 关于THIS_FILE

    VC++中本身就有内存泄漏检查的机制,可以在向导生成的支持MFC的工程中看到如下代码:  #ifdef _DEBUG  #define new DEBUG_NEW  #undef THIS_FILE  ...

  10. Golang学习 - bufio 包

    ------------------------------------------------------------ // bufio 包实现了带缓存的 I/O 操作 -------------- ...