unity3D-游戏/AR/VR在线就业班 C#入门字符串学习笔记

unity3D-游戏/AR/VR在线就业班 C#入门字符串学习笔记
点击观看视频学习:http://edu.csdn .NET /lecturer/107

一、字符串——string

String是引用类型,本质是一个char类型的数组

using System;

namespace Lesson10
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //字符串string本质上是一个char类型的数组
//            char[] c=new char[3];
//            c[0]="A";
//            c[1]="B";

            string str = "ABCD";
            //可以使用下标索引字符串中的字符元素
            Console.WriteLine(str[2]);

            //字符类型
//            char c="A";
//            Console.WriteLine (c);

            //用加法运算符连接两个字符串
//            string s1 = "Hello,";
//            string s2 = "lanou!";
            //Console.WriteLine (s1+s2);
            //适用== 来对比是否完全相等

//            string s1 = "Hello,";
//            string s2 = "lanou!";
//            if (s1 == s2) {
                
//                Console.WriteLine ("文本内容完全相等");
//            } else {
//                Console.WriteLine ("文本内容完全不相等");
//            }



        }
    }
}

字符串方法和属性

using System;

namespace Lesson10
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            string str = "12/345/637/89";
            //检测字符串中是否包含指定的字符串;
            bool b=str.Contains("305");
            Console.WriteLine (b);
            //用来返回字符串中,首次出现指定字符的下标位置
            int i = str.IndexOf ("3");
            Console.WriteLine (i);
            //从指定下标位置,删除后面的字符串
            string ss= str.Remove (3);
            Console.WriteLine (ss);
            //删除字符串
            string s1= str.Remove (3,5);
            Console.WriteLine (s1);

            //替换指定的字符串或字符
            string s=str.Replace("3","X");
            Console.WriteLine (s);

            //分割字符串
            string [] strs=    str.Split(new char[]{'/'},4);
    
            foreach(string temps in strs ){
                
//                Console.WriteLine (temps);
                
            }
            //获取字符串
            string ts=str.Substring(4,3);
            Console.WriteLine (ts);

        }
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值