What are the methods of intercepting strings in C #
This article introduces the relevant knowledge of "what are the methods of intercepting strings in C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First: intercept with split based on a single delimited character
Cash disk website production Q
String st= "GT123_1"
String [] sArray=st.split ("_")
/ / you can get sArray [0] = "GT123", sArray [1] = "1"
The second: using multiple characters to separate strings
String str = "GTAZB_JiangjBen_123"
String [] sArray = str.Split (new char [2] {'jacks,' _'})
Foreach (string e in sArray)
{
Console.WriteLine (e)
}
/ / get sArray [0] = "GTAZB", sArray [1] = "Jiang", sArray [2] = "Ben", sArray [3] = "123"
Third: intercept strings according to strings or string groups
Copy the code
String str = "GTAZB_JiangjBen_123"
String [] sArray = str.Split (new string [] {"Ji", "jB"}, StringSplitOptions.RemoveEmptyEntries)
Foreach (string e in sArray)
{
Console.WriteLine (e)
}
/ / get sArray [0] = "GTAZB_", sArray [1] = "ang", sArray [2] = "en_123"
This is the end of the content of "what are the methods of intercepting strings in C#". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!