当前位置:网站首页>String字符串的使用你都知道了吗?
String字符串的使用你都知道了吗?
2022-07-22 18:07:00 【Glunn】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string name = “我爱北京天安门”;
//Replace 替换单个字符或者多个字符串
//string中字符用’’,字符串用"".
name = name.Replace(“爱”, “不爱”);
Console.WriteLine(name);
string name1 = " 我爱北京天安门 ";
name1 = name.Trim();
Console.WriteLine(name1);
//StringBuilder是可改变大小的字符序列,多个字符组成字符序列,
//字符序列和字符串是同一个意思。
//二者的区别在于,string类型的字符串是常量,字符串创建后不允许修改,
//而StringBuilder 类型的字符串是可变的
StringBuilder myname = new StringBuilder("abc", 3);
Console.WriteLine(myname);
//改变myname的值
myname = new StringBuilder("123456", 6);
Console.WriteLine(myname);
//Append添加
myname = myname.Append("asd");
Console.WriteLine(myname);
string name2 = "qwe";
name2 = name2.ToUpper();//变大写
Console.WriteLine(name2);
name2 = name2.ToLower();//变小写
Console.WriteLine(name2);
string name3 = "qweasd";
name3 = name3.Substring(2, 2);//截取(位置(下标从零开始,往后数几位),往后数几位)
Console.WriteLine(name3);
name3 = string.Format("q{0}ea{1}d","qwe","asd");//占位符号的应用,Format
Console.WriteLine(name3);
int a = name3.IndexOf("s");//查找字符的位置
Console.WriteLine(a);
//Insert插入(下标为几开始插入,插入的内容)
name2 = name2.Insert(1, "1f3");
Console.WriteLine(name2);
//查找是否有这个字符串
bool i = name1.Contains("爱");
Console.WriteLine(i); ;
Console.ReadKey();
}
}
}
边栏推荐
- leetcode-买卖股票的最佳时机含手续费
- Swap parity bits in binary bits
- Leetcode-309. the best time to buy and sell stocks includes the freezing period
- Mrs +apache Zeppelin makes data analysis more convenient
- APB protocol details vs. 3.0-4.0-5.0
- Leetcode-932. beautiful array
- 交换二进制位中的奇偶位
- leetcode-241.为运算表达式设计优先级
- Leetcode-53. maximum subarray and
- CreateProcess output redirection
猜你喜欢

“拨”出数位上的数字 - 多种思路实现反向输出一个四位数

交换二进制位中的奇偶位

Unity创建FPS监视

C语言实现三子棋

Greatest common divisor and least common multiple

Exchange variable values with and without pointers in C language

Exercise + floating point stored in memory

Code random notes_ Linked list_ 160 intersecting linked list

练习+浮点型在内存中存储

Leetcode-343. integer splitting
随机推荐
Detailed explanation of advanced data types in C language
[Err] 1064 - You have an error in your SQL syntax;
大一暑假实习day7总结
递归函数实现素数判断
C语言基础 - 字符串/字符数组最易错考点
leetcode-343. 整数拆分
Fundamentals of C language - the most error prone test point of string / character array
Recursive function to realize prime number judgment
My redis collation
Application and grouping of regular expressions
最大公约数和最小公倍数
Detailed explanation of Axi agreement
Super detailed - how to understand the expression while (scanf ("%d", & Num)! = EOF) in C language?
day6_ Jigsaw puzzle follow-up - switch interface, random pictures and package exe
Leetcode-384. clutter array
Common libcurl methods post get Download
leetcode-932.漂亮数组
leetcode-172.阶乘后的零
MRS +Apache Zeppelin,让数据分析更便捷
leetcode-415.字符串相加