1 string segmentation
String url ="[Url] http: // asdfsfd [/url] [*] ASDF [*] asdfsdf [*]";
String [] SSS = getstring (URL, "[*]");
Foreach (string STR in SSS)
{
Response. Write (Str. tostring () + "");
}
Private string [] getstring (string STR, string cutstr)
{
Char [] cutchar = cutstr. tochararray ();
String [] sarray = Str. Split (cutchar );
Return sarray;
}
2 string Truncation
Public static string getfirststring (string stringtosub, int length)
{
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]);
Nlength = nlength + 1;
}
If (nlength> length)
{
Iscut = true;
Break;
}
}
If (iscut)
Return sb. tostring () + "...";
Else
Return sb. tostring ();
}
3. substring Function
String tmp2 = tmp1.substring (0, 3 );
Equivalent to mid in VB.net
Tring STR = "abcdefg ";
String str1 = Str. substring (2, 3); // str1 = "CDE"
4. C # Can I determine whether a character exists in a string? For example, does "akkk * KKK" have "*"?
String S = "akkk * KKK ";
Int I = S. indexof ("*");
If (I! =-1) include
Else does not contain
5. Right-aligned characters in this instance. Fill in the specified UNICODE character on the left to reach the specified total length.
[C #] Public String padleft (INT, char );
STR = "256 ";
STR = Str. padleft (5, "0"); // STR = "00256"