// Alignment
Console. writeline ("{0,-20} {1}", "fafdaafd:", "213 ");
Console. writeline ("{0,-20} {1}", "fdfaa:", "13 ");
// Add an English letter T, which can be aligned
Console. writeline ("{0,-20} {1}", "fafdatafd:", "213 ");
Console. writeline ("{0,-20} {1}", "fdfaa:", "13 ");
// Add one Chinese character to reduce the number of two letters, which can be aligned
Console. writeline ("{0,-20} {1}", "fafdfd my Ben:", "213 ");
Console. writeline ("{0,-20} {1}", "fdfaa:", "13"); // Add a Chinese character to reduce one letter, which cannot be aligned
Console. writeline ("{0,-20} {1}", "fafdaafd my runner:", "213 ");
Console. writeline ("{0,-20} {1}", "fdfaa:", "13 ");
The following result is displayed in the message box: Solution:
Public class qstring
{
String S;
/// <Summary>
/// Create an instance
/// </Summary>
/// <Param name = "S"> </param>
Public qstring (string S)
{
This. S = s;
}
/// <Summary>
/// To be formatted
/// </Summary>
/// <Param name = "length"> length </param>
/// <Param name = "CHR"> complement </param>
/// <Returns> formatted data </returns>
/// <Remarks>
/// Based on English letters, the maximum length and actual length are used to calculate the complement length.
/// For example, C 20
/// C I 20-1
/// C multiple me 20-3
/// </Remarks>
Public String padleft (INT length, char CHR)
{
Return S. padleft (length-new system. Text. regularexpressions. RegEx (@ "[\ u4e00-\ u9fa5]"). Matches (s). Count, CHR );}
/// <Summary>
/// To be formatted
/// </Summary>
/// <Param name = "length"> length </param>
/// <Param name = "CHR"> complement </param>
/// <Returns> formatted data </returns>
/// <Remarks>
/// Based on English letters, the maximum length and actual length are used to calculate the complement length.
/// For example, C 20
/// C I 20-1
/// C multiple me 20-3
/// </Remarks>
Public String padright (INT length, char CHR)
{
Return S. padright (length-new system. Text. regularexpressions. RegEx (@ "[\ u4e00-\ u9fa5]"). Matches (s). Count, CHR );}
} Msgbox is not applicable to a large number of practical applications that can be used in many cases. Using system;
Using system. Collections. Generic;
Using system. Text; namespace qoushui. dll
{
Public class qstring
{
String S;
/// <Summary>
/// Create an instance
/// </Summary>
/// <Param name = "S"> </param>
Public qstring (string S)
{
This. S = s;
Hcount = reg. Matches (s). count;
} System. Text. regularexpressions. RegEx Reg = new system. Text. regularexpressions. RegEx (@ "[\ uff00-\ Uffff \ u4e00-\ u9fa5]");
Int hcount = 0; // <summary>
/// To be formatted
/// </Summary>
/// <Param name = "length"> length </param>
/// <Param name = "CHR"> complement </param>
/// <Returns> formatted data </returns>
/// <Remarks>
/// Based on English letters, the maximum length and actual length are used to calculate the complement length.
/// For example, C 20
/// C I 20-1
/// C multiple me 20-3
/// </Remarks>
Public String padleft (INT length, char CHR)
{
If (length-S. Length-Reg. Matches (s). Count <0)
Length = S. Length + Reg. Matches (s). count;
Return S + new string (CHR, length-S. Length-Reg. Matches (s). Count );
}
/// <Summary>
/// To be formatted
/// </Summary>
/// <Param name = "length"> length </param>
/// <Param name = "CHR"> complement </param>
/// <Returns> formatted data </returns>
/// <Remarks>
/// Based on English letters, the maximum length and actual length are used to calculate the complement length.
/// For example, C 20
/// C I 20-1
/// C multiple me 20-3
/// </Remarks>
Public String padright (INT length, char CHR)
{
If (length-S. Length-Reg. Matches (s). Count <0)
Length = S. Length + Reg. Matches (s). count;
Return new string (CHR, length-S. Length-Reg. Matches (s). Count) + S;
}
}
}
Publish by note