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. STM32 + RT Thread OS 学习笔记[三]

    RTGUI 据说RTGUI是多线程的,因此与RT-Thread OS的耦合度较高,有可能要访问RT-Thread的线程控制块.如果要移植到其它OS,估计难度较大.目前还处于Alpha状态,最终将会包含 ...

  2. 习总强调网络安全 ,咱们国产SSL证书必须加快普及速度

    上海(2014 年 2 月 27 日)—— 央视新闻联播 27 日报道中央网络安全和信息化领导小组于当日成立的消息及习总在该小组首次会议上的重要讲话.据悉,该小组由习总任小组长,李克强.刘云山任副组长 ...

  3. python中使用list作为默认参数且调用时不给其赋值的问题

    最近在写代码时发现一个有趣的地方,当python中的函数使用list作为默认参数且调用时不给其赋值时,无法通过在函数中将其赋值为[]来达到清空此默认参数的目的.按照道理来说,函数f1中的list为局部 ...

  4. hihocoder #1179 : 永恒游戏 暴力

    #1179 : 永恒游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/11 ...

  5. C#调用Excel VBA宏

    近日的一系列工作是做网站的营运维护,因此做了大量的支持工具.有Excel中写VBA的,也有直接C#做的工具.有时需要在C#中执行Excel VBA宏,甚至有时还需要在执行了VBA宏之后,获取返回值再进 ...

  6. Spark1.0.0 开发环境高速搭建

          在本系列博客中.为了解析一些概念.解析一些架构.代码測试.搭建了一个实验平台.例如以下图所看到的:       本实验平台是在一台物理机上搭建的.物理机的配置是16G内存,4核8线程CPU ...

  7. android获取/更改gps和WIFI状态

    一.WIFI状态的获取和更改 适用于 SDK1.0 , SDK1.5 1.获取WIFI状态 方法1:通过WifiManager进行操作 1WifiManager wifiManager = (Wifi ...

  8. JS的setTimeout函数第一个参数问题

    setTimeout的第一个参数只能放一个无参的函数,更像放了一个函数指针在那里,如果要放带参数的话,就要拿个匿名函数包裹一下

  9. careercup-高等难度 18.1

    18.1  编写一个函数,将两个数字相加,不得使用+或其他算术运算符. int add(int a,int b) { ) return a; int sum=a^b; ; return add(sum ...

  10. 配置apache虚拟主机的实例总结

    如何实现apache虚拟主机配置. 1.基于ip地址的虚拟主机Listen 80<VirtualHost 172.20.30.40> DocumentRoot /home/httpd/ht ...