當前位置: 首頁>>代碼示例>>C#>>正文


C# String.PadRight方法代碼示例

本文整理匯總了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();
            }
        }
開發者ID:keymorrislane,項目名稱:SEMC_SQL-for-Excel,代碼行數:37,代碼來源:AESModel.cs

示例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;
        }
開發者ID:uwitec,項目名稱:wms_rfid,代碼行數:27,代碼來源:StrHandle.cs

示例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;
        }
開發者ID:jagrem,項目名稱:Pash,代碼行數:35,代碼來源:FormatTableShape.cs

示例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();
        }
開發者ID:wizardbeard,項目名稱:ConsoleDraw,代碼行數:26,代碼來源:Alert.cs

示例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);
 }
開發者ID:curasystems,項目名稱:externals,代碼行數:13,代碼來源:Trace.cs

示例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;
 }
開發者ID:Ermelber,項目名稱:EveryFileExplorer,代碼行數:30,代碼來源:PatriciaTreeGenerator.cs

示例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());

            }
        }
開發者ID:davep1ke,項目名稱:roboto,代碼行數:35,代碼來源:message.cs

示例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);
 }
開發者ID:christal1980,項目名稱:wingsoa,代碼行數:7,代碼來源:CryptographyHelper.cs

示例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;
        }
開發者ID:Aevin1387,項目名稱:LocalChat,代碼行數:28,代碼來源:Message.cs

示例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;
            }
        }
開發者ID:ochulof,項目名稱:ProjectC,代碼行數:27,代碼來源:Logging.cs

示例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();
        }
開發者ID:CaseyMcCordAnderson,項目名稱:TextUI,代碼行數:25,代碼來源:TuiConfirm.cs

示例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);
        }
開發者ID:menohack,項目名稱:GlebForgeServer,代碼行數:8,代碼來源:Player.cs

示例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));
        }
開發者ID:Duke-Jones,項目名稱:ED-IBE,代碼行數:12,代碼來源:TextHelper.cs

示例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;
 }
開發者ID:Aevin1387,項目名稱:LocalChat,代碼行數:13,代碼來源:UserList.cs

示例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);
        }
開發者ID:keymorrislane,項目名稱:SEMC_SQL-for-Excel,代碼行數:49,代碼來源:AESModel.cs


注:本文中的System.String.PadRight方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。