字符串

作者: 妈妈说喝牛奶能长个 | 来源:发表于2017-08-07 14:46 被阅读0次

"hello world"字符串  ' h'字符  空格也算字符

bool取值false和true,是0和1的区别;false可以代表0,但true有很多种,并非只有1。

c#中 布尔类型非0为真,只有0为假

string  char

string str = "string";

字符串长度

int a = str.Length;

Console.WriteLine ("{0}",a);  //a = 6

如何判断两个字符串恒等

string  str1  = "ni hao";

if (str1 == str){

 }

bool b = str1.Equals (str);

if (b) {

}

字符串的拼接

string str2 = str + str1;  //"1"+" "+"2" = "1 2";

string ZhangHao = "ni hao";

Console.WriteLine ("输入帐号");

string ZhangHao1 = Console.ReadLine ( );

if (ZhangHao1 == ZhangHao) {

               Console.WriteLine ("帐号正确");

} else {

               Console.WriteLine ("错误");

}

//登录

string name = "admin",password = "123456";

Console.WriteLine ("输入帐号");

string user_name = Console.ReadLine ( );

Console.WriteLine ("输入密码");

string user_password = Console.ReadLine ( );

// if (user_name == name && user_password == password) {

//                Console.WriteLine ("真聪明");

// } else {

//                Console.WriteLine ("大傻逼");

// }

if (user_name == name) {

      if (user_password == password) {

                  Console.WriteLine ("小宝贝真聪明");

} else {

                  Console.WriteLine ("密码错了大傻逼");

}

} else {

                  Console.WriteLine ("用户名错了臭傻逼");

}

//判断某头字符串是否包含某个字符串

string str = "hellow";

str.Contains ("el");

bool b = str.Contains ("el");

Console.WriteLine ("{0}",b);            //  true

//是否以某一个字符串结尾

str.EndsWith ("o");

//是否以某一个字符串开始

str.StartsWith ("h");

//右对齐

string newstar = str.PadLeft(15);

Console.WriteLine (newstar);

string str1 = "China";

string str2 = "English";

Console.WriteLine (str1.PadLeft(5));    //左缩进5个字符

Console.WriteLine (str2.PadLeft(5));

//替换

string str = "hellow";

;string str3 = str.Replace ("ll","abcd");

Console.WriteLine (str3);        //heabcdow

//转换为大写

string upper_Str = str.ToUpper();

Console.WriteLine (upper_Str);    //HELLOW

//a转A   ASCLL码控制

char n = (char)((int)'a' - 32);

Console.WriteLine ("{0}",n);    //A

string str = "    hellow world ";

//从当前的字符串中去移除头部和尾部的空白字符

string str1 = str.Trim();

Console.WriteLine ("{0}",str1);

//截取字符串

string str2 = str1.Substring(4,4);    //从第4个字符开始(不包含第4个) 截取长度为4

Console.WriteLine("{0}",str2);

Console.WriteLine (str.Remove (1,3));  //删除下标为1 后面三个数(包括1)

Console.WriteLine(str.Substring(1,3));  //截取下标为1 后面三个数(包括1);


//分割字符串

string str = "Stritritring ";

char[] chs = { 'i' };           //以i作为分割标识 

string[] strs = str.Split(chs);

foreach (string s in strs) {

          Console.WriteLine (s);        //Str tr tr ng

}

相关文章

  • Javascript知识点整合

    字符串 单行字符串: ‘字符串’或“字符串” 多行字符串: `多行字符串` 字符串操作: 字符串连接‘+’号 长度...

  • C++基础字符串

    字符串的构造 字符串特性描述 字符操作 字符串赋值 字符串连接 字符串比较 字符串查找 字符串替换 字符串删除 字...

  • iOS中的NSString与NSMutableString

    字符串的创建 字符串读写 字符串的比较 字符串的搜索 字符串截取 字符串替换 字符串与路径 字符串转换 NSMut...

  • iOS NSString用法总结

    字符串属性 字符串截取 字符串比较 字符串搜索 字符串拼接 字符串基本类型转换 字符串分行,分段 字符串列举(按条...

  • php 字符串常见方法汇总

    字符串拼接 字符串检索 字符串截取 字符串替换 字符串大小写转化 字符串转数组 字符串格式化

  • iOS 字符串截取、iOS 字符串替换、iOS 字符串分隔、iO

    iOS之字符串截取、iOS 字符串替换、iOS字符串分隔、iOS之字符串匹配、截取字符串、匹配字符串、分隔字符串 ...

  • PHP中字符串函数库常用函数解析 -- PHP 学习 (十一)

    常用字符串函数分类: 字符串长度, 字符串查找, 字符串大小写转换, 字符串截取, 字符串 ASCII, 字符串加...

  • Kotlin语言(二):字符串类型

    1、字符串定义 2、字符串删除空格 3、字符串比较 4、字符串切割 5、字符串截取 6、字符串替换 7、字符串模板

  • 字符串扩展

    求字符串大小 字符串解码、转换 字符串截取 字符串汉字处理 字符串 Mac地址 字符串进制转换

  • 2020-09-30字符串

    day8-字符串 字符串的操作 in 和 not in字符串1 in 字符串2 - 判断字符串1是否是字符串...

网友评论

      本文标题:字符串

      本文链接:https://www.haomeiwen.com/subject/wzqalxtx.html