当前位置:网站首页>String class
String class
2022-07-03 08:05:00 【Luckyᕙ(⇀‸↼‵‵)ᕗ】
== and Equals The difference between
1、 Value type
== and Equals The contents of the comparison are consistent , It's all comparative content
string a = "123";// value
Console.WriteLine(a=="123");
Console.WriteLine(a.Equals("123"));
2、 Reference type
==: Compare whether the first address is equal Equals: The comparison is whether the values are equal
char[] x={ '1','2','3'};
string b = newstring(x);// quote
Console.WriteLine(b=="123");
Console.WriteLine(b.Equals("123"));
1) String comparison
Compare(str1, str2)
str1.CompareTo(str2)
string a = "hello",b="Hello",c="hello";
Console.WriteLine(a.CompareTo(b));//-1
Console.WriteLine(string.Compare(a,b));//-1
Console.WriteLine(a.CompareTo(c));//0
- String lookup
(1)Contains(Findstr): Find whether the specified string contains a string Findstr, The return value of bool type , That is, only
true and false.
(2)、IndexOf(Findstr): lookup FindStr First occurrence in string , The return value is the first occurrence
The subscript , If not found, return -1.
(3)、LastIndexOf(FindStr): lookup FindStr Last occurrence in string , Return value is last
The subscript of one occurrence , If not found, return -1.
Console.WriteLine(a.Contains("lo"));//true
Console.WriteLine(a.IndexOf('e'));//1
Console.WriteLine(a.LastIndexOf('l'));//3
- String truncation
SubString(StartIndex): Subscript in string from StartIndex Start all subsequent strings .
SubString(StartIndex, Len): Subscript in string from StartIndex Start the back Len A string of length .
Console.WriteLine(a.Substring(1));//ello
Console.WriteLine(a.Substring(1,3));//ell
- Segmentation of strings
Split(SplitCh): The string Press SplitCh Segmentation , Its return value is an array of strings .
string d=" Hoe standing grain gradually pawning a midday # Sweat dripping under the grass # Who knows what's on the plate # Every grain is hard ";
string[] e = d.Split('#');
for (int i = 0; i < e.Length; i++)
{
Console.WriteLine(e[i]);
}
- String merging
string.Concat(str1, str2, …., strn): take n String connection , There is no connector in the middle
“+” Connection symbol
string f = "world";
Console.WriteLine(a+f);
Console.WriteLine(1+2+3+a);//6hello
Console.WriteLine(a+1+2+3);//hello123
Console.WriteLine(string.Concat(a,f));//helloworld
- String replacement
Replace(oldStr, newStr): use newStr To replace... In the string oldStr
Console.WriteLine(a.Replace("he","HE"));//HEllo
- String insertion
Insert(index, str):index Is where you need to insert ,str Is the character to insert
Console.WriteLine(a.Insert(1,"ww"));//hwwello
- Deletion of string
Trim(): Delete the spaces at the beginning and end of the string
Remove(Start):Start For the starting position to be deleted , The method is to delete all characters after the position
Remove(Start, Len):Len It refers to the length to be deleted , Different from the above format, it starts from the starting position
Delete Len Characters
string s = " aaa bbb ccc ";
Console.WriteLine(s.Trim());//aaa bbb ccc
Console.WriteLine(s.Remove(6));// aaa b
Console.WriteLine(s.Remove(2,7));// aaccc
9) String case conversion
ToLower(): Convert the string to lowercase
ToUpper(): Convert string to uppercase
10)string.Format()
string.Format("{0:d}",System.DateTime.Now) // The result is :2021-3-23( The location of the month is not 03)
string.Format("{0:D}",System.DateTime.Now) // The result is :2021 year 3 month 23 Japan
string.Format("{0:f}",System.DateTime.Now) // The result is :2021 year 3 month 23 Japan 15:37
string.Format("{0:F}",System.DateTime.Now) // The result is :2021 year 3 month 23 Japan 15:37:52
string.Format("{0:g}",System.DateTime.Now) // The result is :2021-3-23 15:38
string.Format("{0:G}",System.DateTime.Now) // The result is :2021-3-23 15:39:27
string.Format("{0:m}",System.DateTime.Now) // The result is :3 month 23 Japan
string.Format("{0:t}",System.DateTime.Now) // The result is :15:41
string.Format("{0:T}",System.DateTime.Now) // The result is :15:41:50
边栏推荐
- oracle中的 (+)是什么意思
- Oracle queries grouped by time
- Differences between tp3.2 and tp5.0
- Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
- LwIP learning socket (application)
- PIP uses image website to solve the problem of slow network speed
- 使用 FileChannel 进行文件的复制拷贝
- Static keyword
- Are you still watching the weather forecast on TV?
- L'installateur a été installé avec une erreur inattendue
猜你喜欢

Zohocrm deluge function application time verification

the installer has encountered an unexpected error installing this package
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface

Redis batch startup and shutdown script

Are you still watching the weather forecast on TV?
![[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)](/img/df/a034032e203e7935dafaf8a71cb6c8.jpg)
[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)

freetype库的移植

An article for you to understand - Manchester code

Shader foundation 01

vcs import src < ros2. Repos failed
随机推荐
[at] abc 258G - Triangle 三元組可達-暴力
PIP uses image website to solve the problem of slow network speed
Pat class a 1031 Hello world for u
MAE
Haproxy+kept cluster setup 02
一条通往服务器所有端口的隧道
Oracle queries grouped by time
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
Viz artist advanced script video tutorial -- stringmap use and vertex operation
[MySQL 12] MySQL 8.0.18 reinitialization
Multi traveling salesman problem -- overview of formula and solution process
Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
[at] abc 258G - Triangle 三元组可达-暴力
Worldview satellite remote sensing image data / meter resolution remote sensing image
Static keyword
Storage of data
Differences between tp3.2 and tp5.0
使用 FileChannel 进行文件的复制拷贝
[cocos creator] get the resource UUID
Mutual call between Lua and C #