[Reserved] in C # PadRight function to a specific character in the end of the string to make up the number of bits

String String type process is sometimes insufficient when the string length needs to be specified in the C # development process on the right side to make up a specific character string length, then the method may be used PadRight String class according to the end of the string specific characters make up the digits. PadRight interpretation function is on MSDN: Returns the specified length of the new string, wherein the current string or the end of a space filled specified Unicode character.

For example, the length of the string Code = "ABC", document number according to the service request requires a length of 10 bits, the length is not enough if need be imposed complement processing mode 0 at the end of the string.

string Code=“ABC”;

Code = Code.PadRight (10, '0 ');
After processing the two obtained statement Code value: ABC0000000

The method defined PadRight containing two reload implemented as follows

(1) PadRight (int totalWidth): made up to totalWidth length, padded with spaces to the default method.

(2) PadRight (int totalWidth, char paddingChar): paddingChar specified character string to make up the final length of the string is totalWidth.

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link for the C # function to a particular character in PadRight end of the string to make up small-digit _IT technical interest in the house .

Guess you like

Origin blog.csdn.net/weixin_39650424/article/details/93380472