How to use string in C #
Editor to share with you how to use the string in C#, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
1.C# string segmentation
String url = "http://asdfsfd asdf asdfsdf"; string [] sss = GetString (url, "); foreach (string strin sss) {Response.Write (str.ToString () +");} private string [] GetString (string str,string cutStr) {char [] cutChar = cutStr.ToCharArray (); string [] sArray = str.Split (cutChar); return sArray;}
2.C# string interception
Public static string GetFirstString (string stringToSub, int length) {Regex regex = new Regex ("[\ u4e00 -\ u9fa5] +", RegexOptions.Compiled); char [] stringChar = stringToSub.ToCharArray (); StringBuilder sb = new StringBuilder (); int nLength = 0; bool isCut=false; for (int I = 0; I)
< stringChar.Length; i++) { if (regex.IsMatch((stringChar[i]).ToString())) { sb.Append(stringChar[i]); nLength += 2; } else { sb.Append(stringChar[i]); nLengthnLength = nLength + 1; } if (nLength >Length) {isCut=true; break;}} if (isCut) return sb.ToString () + "..."; else return sb.ToString ();}
3. Take the substring function SubString
String tmp2 = tmp1.SubString (0jue 3); equivalent to mid tring str= "abcdefg" in vb.net; string strstr1=str.Substring (2pr 3); / / str1= "cde"
What function in 4.C# can tell if there is a character in a C # string? For example, does "akkk*kkk" have "*"?
String s = "akkk*kkk"; int I = s.IndexOf ("*"); if (I! =-1) contains else but not else
5. Align the characters in this instance to the right and fill them with the specified Unicode characters on the left to reach the specified total length.
Public string PadLeft (int, char); str = "256"; strstr = str.PadLeft (5," 0 "); / / str =" 00256 "is all the content of this article" how to use strings in C# ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!