本文整理汇总了C#中System.String.PadRight方法的典型用法代码示例。如果您正苦于以下问题:C# String.PadRight方法的具体用法?C# String.PadRight怎么用?C# String.PadRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.PadRight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AESDecryptWithoutVector
/// <summary>
/// AES解密(无向量)
/// </summary>
/// <param name="encryptedBytes">被加密的明文</param>
/// <param name="key">密钥</param>
/// <returns>明文</returns>
public static string AESDecryptWithoutVector(String Data, String Key)
{
Byte[] encryptedBytes = Convert.FromBase64String(Data);
Byte[] bKey = new Byte[32];
Array.Copy(Encoding.UTF8.GetBytes(Key.PadRight(bKey.Length)), bKey, bKey.Length);
MemoryStream mStream = new MemoryStream(encryptedBytes);
//mStream.Write( encryptedBytes, 0, encryptedBytes.Length );
//mStream.Seek( 0, SeekOrigin.Begin );
RijndaelManaged aes = new RijndaelManaged();
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
aes.KeySize = 128;
aes.Key = bKey;
//aes.IV = _iV;
CryptoStream cryptoStream = new CryptoStream(mStream, aes.CreateDecryptor(), CryptoStreamMode.Read);
try
{
byte[] tmp = new byte[encryptedBytes.Length + 32];
int len = cryptoStream.Read(tmp, 0, encryptedBytes.Length + 32);
byte[] ret = new byte[len];
Array.Copy(tmp, 0, ret, 0, len);
return Encoding.UTF8.GetString(ret);
}
finally
{
cryptoStream.Close();
mStream.Close();
aes.Clear();
}
}
示例2: GetStringWith
public static String GetStringWith(String str, int length)
{
str = str.PadRight(length, " "[0]);
char [] strs = str.ToCharArray();
str = "";
int i = 0;
foreach (char s in strs)
{
str = str + s.ToString();
i = i + Encoding.Default.GetByteCount(s.ToString());
if (i == length || i == length -1 )
{
str = str.Substring(0, str.Length - 2) + " ";
break;
}
}
str = str.PadRight(length, " "[0]);
int bytecount = Encoding.Default.GetByteCount(str);
int strlength = str.Length;
int zh_count = bytecount - strlength;
str = str.Substring(0, length - zh_count);
return str;
}
示例3: Format
public static String Format(FormatElement formatable)
{
String _row = new String(new char[] { '\0' });
foreach (String _cell in formatable.Values)
{
// If the info doesn't fit into the column, strip it down and fit it in
if (_cell.Length > formatable.ColumnSize)
{
_row += _cell.Substring(0, (formatable.ColumnSize - 4)) + "... ";
}
else
{
_row += _cell;
_row.PadRight(formatable.ColumnSize);
}
}
if (formatable.isHeader)
{
_row += "\n";
foreach (String _cell in formatable.Values)
{
// Make the underlines for the headers
_row.PadRight((_row.Length + _cell.Length), '-');
// Space out the underlines
_row.PadRight((_row.Length + (formatable.ColumnSize - _cell.Length)));
}
}
return _row;
}
示例4: Create
private void Create(String Message, Window parentWindow)
{
var count = 0;
while ((count*45) < Message.Count())
{
var splitMessage = Message.PadRight(textLength * (count + 1), ' ').Substring((count * textLength), textLength);
var messageLabel = new Label(splitMessage, PostionX + 2 + count, PostionY + 2, "messageLabel", this);
Inputs.Add(messageLabel);
count++;
}
/*
var messageLabel = new Label(Message, PostionX + 2, PostionY + 2, "messageLabel", this);
messageLabel.BackgroundColour = BackgroundColour;*/
okBtn = new Button(PostionX + Height - 2, PostionY + 2, "OK", "OkBtn", this);
okBtn.Action = delegate() { ExitWindow(); };
Inputs.Add(okBtn);
CurrentlySelected = okBtn;
Draw();
MainLoop();
}
示例5: writeToDebug
/// <summary>
/// Writes the trace to the Debug
/// </summary>
/// <param name="type">Type of trace</param>
/// <param name="module">Module responsible for the error</param>
/// <param name="message">The message to be displayed</param>
private static void writeToDebug(String type, String module, String message)
{
int space1 = 10;
int space2 = 45;
//Debug.WriteLine(System.DateTime.Now.ToString("HH:mm:ss:ff") + " " + type.PadRight(space1,' ') + module.PadRight(space2,' ') + message);
System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString("HH:mm:ss:ff") + " " + type.PadRight(space1,' ') + module.PadRight(space2,' ') + message);
}
示例6: AddPatTreeNode
public PatTreeNode AddPatTreeNode(String Name, int Index)
{
Name = Name.PadRight(StringLength, '\0');
PatTreeNode n = new PatTreeNode();
n.name = Name;
PatTreeNode CurNode = Nodes[0];
PatTreeNode leftNode = CurNode.left;
uint bit = (uint)(StringLength * 8) - 1;
while (CurNode.refbit > leftNode.refbit)
{
CurNode = leftNode;
leftNode = GetBit(Name, leftNode.refbit) ? leftNode.right : leftNode.left;
}
while (GetBit(leftNode.name, bit) == GetBit(Name, bit)) bit--;
CurNode = Nodes[0];
leftNode = CurNode.left;
while ((CurNode.refbit > leftNode.refbit) && (leftNode.refbit > bit))
{
CurNode = leftNode;
leftNode = GetBit(Name, leftNode.refbit) ? leftNode.right : leftNode.left;
}
n.refbit = bit;
n.left = GetBit(Name, n.refbit) ? leftNode : n;
n.right = GetBit(Name, n.refbit) ? n : leftNode;
if (GetBit(Name, CurNode.refbit)) CurNode.right = n;
else CurNode.left = n;
n.idxEntry = Index;
Nodes.Add(n);
return n;
}
示例7: message
public message(JToken update_TK)
{
try
{
//get the message details
message_id = update_TK.SelectToken(".message_id").Value<long>();
chatID = update_TK.SelectToken(".chat.id").Value<long>();
chatName = getNullableString(update_TK.SelectToken(".chat.title"));
text_msg = update_TK.SelectToken(".text").Value<String>();
//text_msg = (String)JsonConvert.DeserializeObject(text_msg);
userID = update_TK.SelectToken(".from.id").Value<long>();
userHandle = getNullableString(update_TK.SelectToken(".from.username"));
userFirstName = getNullableString(update_TK.SelectToken(".from.first_name"));
userSurname = getNullableString(update_TK.SelectToken(".from.last_name"));
userFullName = userFirstName + " " + userSurname;
//in reply to...
JToken replyMsg_TK = update_TK.SelectToken(".reply_to_message");
if (replyMsg_TK != null)
{
isReply = true;
replyOrigMessage = replyMsg_TK.SelectToken(".text").Value<String>();
replyOrigUser = replyMsg_TK.SelectToken(".from.username").Value<String>();
replyMessageID = replyMsg_TK.SelectToken(".message_id").Value<long>();
}
Roboto.Settings.stats.logStat(new statItem("Incoming Msgs", typeof(TelegramAPI)));
Roboto.log.log("Message:" + userFullName.PadRight(17, " "[0] ) + " -> " + text_msg, logging.loglevel.low);
}
catch (Exception e)
{
Console.WriteLine("Error parsing message " + e.ToString());
}
}
示例8: FormatKey
private static byte[] FormatKey(String key)
{
//a chave tem que ter entre 3 e 8 caracteres
if (key.Length > 8) { key = key.Substring(0, 8); }
key = key.PadRight(8, 'X');
return new UnicodeEncoding().GetBytes(key);
}
示例9: setupPacket
public static char[] setupPacket(String command, String pUsername,
String sequence, char encFlag,
String message)
{
String strMessage = command + pUsername.PadRight(32, '\0');
if (command == "BCST" || command == "BACK") {
// do nothing, default strMessage
}
else if (command == "MESG") {
strMessage += sequence.PadLeft(5, '0') + encFlag +
message.PadRight(140, '\0');
}
else if (command == "MACK") {
strMessage += sequence.PadLeft(5, '0');
}
char[] partialMessage = strMessage.ToCharArray(0, strMessage.Length);
char[] fullMessage = new char[strMessage.Length + 1];
partialMessage.CopyTo(fullMessage, 0);
fullMessage[strMessage.Length] = '\0';
/* Garbage Collection */
partialMessage = null;
strMessage = null;
return fullMessage;
}
示例10: WriteLine
public void WriteLine(String App, String Line)
{
StreamWriter writer = null;
try
{
using (writer = new StreamWriter(FileName, true))
{
String prefix = DateTime.UtcNow.ToString("dd/MM/yyyy hh:mm:ss UTC") + " : App : " + App.PadRight(20) + " - ";
Line = prefix + Line;
Line = Line.Replace("/n", "/n" + prefix);
writer.WriteLine(Line);
writer.Flush();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
writer.Close();
writer = null;
}
}
示例11: Create
private void Create(String Message, TuiWindow parentTuiWindow)
{
var count = 0;
while ((count * 45) < Message.Count())
{
var splitMessage = Message.PadRight(textLength * (count + 1), ' ').Substring((count * textLength), textLength);
var messageLabel = new TuiLabel(splitMessage, X + 2 + count, Y + 2, "messageLabel", this);
AddControl(messageLabel);
count++;
}
okBtn = new TuiButton(X + Height - 2, Y + 2, "OK", "OkBtn", this);
okBtn.Action = delegate() { Result = true; Close(); };
cancelBtn = new TuiButton(X + Height - 2, Y + 8, "Cancel", "cancelBtn", this);
cancelBtn.Action = delegate() { Close(); };
AddControl(okBtn);
AddControl(cancelBtn);
CurrentlySelected = okBtn;
Draw();
}
示例12: Player
public Player(Position position, Velocity velocity, String name, String password)
{
this.Position = position;
this.Velocity = velocity;
this.Name = name;
this.Password = password.PadRight(128);
}
示例13: FixedLength
public string FixedLength(String shortString, Font font, int fullLength)
{
Int32 spaceWidth = 0;
if(!spaceWidthCache.TryGetValue(font, out spaceWidth))
{
spaceWidth = TextRenderer.MeasureText(" ", font).Width;
spaceWidthCache.Add(font, spaceWidth);
}
return shortString.PadRight((Int32)Math.Round(((Double)fullLength - (Double)TextRenderer.MeasureText(shortString, font).Width) / (Double)spaceWidth, 0));
}
示例14: setupPacket
public char[] setupPacket(String command, String pUsername, String sequence,
char encFlag, String message)
{
String strMessage = command + pUsername.PadRight(32, '~') +
sequence.PadRight(5, '~') + encFlag +
message.PadRight(140, '~');
char[] partialMessage = strMessage.ToCharArray(0, 182);
char[] fullMessage = new char[183];
partialMessage.CopyTo(fullMessage, 0);
fullMessage[182] = '\0';
partialMessage = null;
return fullMessage;
}
示例15: AESDecryptWithVector
/// <summary>
/// AES解密
/// </summary>
/// <param name="Data">被解密的密文</param>
/// <param name="Key">密钥</param>
/// <param name="Vector">向量</param>
/// <returns>明文</returns>
public static String AESDecryptWithVector(String Data, String Key, String Vector)
{
Byte[] encryptedBytes = Convert.FromBase64String(Data);
Byte[] bKey = new Byte[32];
Array.Copy(Encoding.UTF8.GetBytes(Key.PadRight(bKey.Length)), bKey, bKey.Length);
Byte[] bVector = new Byte[16];
Array.Copy(Encoding.UTF8.GetBytes(Vector.PadRight(bVector.Length)), bVector, bVector.Length);
Byte[] original = null; // 解密后的明文
Rijndael Aes = Rijndael.Create();
try
{
// 开辟一块内存流,存储密文
using (MemoryStream Memory = new MemoryStream(encryptedBytes))
{
// 把内存流对象包装成加密流对象
using (CryptoStream Decryptor = new CryptoStream(Memory,
Aes.CreateDecryptor(bKey, bVector),
CryptoStreamMode.Read))
{
// 明文存储区
using (MemoryStream originalMemory = new MemoryStream())
{
Byte[] Buffer = new Byte[1024];
Int32 readBytes = 0;
while ((readBytes = Decryptor.Read(Buffer, 0, Buffer.Length)) > 0)
{
originalMemory.Write(Buffer, 0, readBytes);
}
original = originalMemory.ToArray();
}
}
}
}
catch
{
original = null;
}
return Encoding.UTF8.GetString(original);
}