本文整理汇总了C#中System.String.PadLeft方法的典型用法代码示例。如果您正苦于以下问题:C# String.PadLeft方法的具体用法?C# String.PadLeft怎么用?C# String.PadLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.PadLeft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ShowAnswer
public void ShowAnswer(int page, int index, String answer, int points)
{
if (page == 0)
{
StringBuilder sb = new StringBuilder();
sb.Append(answer);
if (sb.Length < 10)
{
for (int i = 10 - sb.Length; i > 0; i--)
{
sb.Append(' ');
}
}
sb.Append(' ');
sb.AppendFormat("{0:00} ", points);
(answerStackA.Children[index] as Label).Content = sb.ToString();
}
else
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0:00} ", points);
sb.Append(answer.PadLeft(10));
(answerStackB.Children[index] as Label).Content = sb.ToString();
}
}
示例3: GetIodcFromSapDataBase
/// <summary>
/// 根据IDOC编号从SAP系统里读取一个idoc
/// </summary>
/// <param name="idocNumber"></param>
/// <returns></returns>
public Idoc GetIodcFromSapDataBase(String idocNumber)
{
SAPINT.Utils.ReadTable idocReadItem = null;
SAPINT.Utils.ReadTable idocReadHeader = null;
DataTable dtIdocItem = new DataTable();
DataTable dtIdocHeder = new DataTable();
idocNumber = idocNumber.TrimStart('0');
String criteria = idocNumber.PadLeft(16, '0');
criteria = String.Format("DOCNUM = '{0}'", criteria);
String readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction();
idocReadItem = new Utils.ReadTable(SystemName);
idocReadItem.TableName = "EDID4";
idocReadItem.SetCustomFunctionName(readTableFunction);
idocReadItem.AddCriteria(criteria);
idocReadItem.Run();
dtIdocItem = idocReadItem.Result;
if (dtIdocItem.Rows.Count == 0)
{
idocReadItem = new Utils.ReadTable(SystemName);
idocReadItem.TableName = "EDID2";
idocReadItem.SetCustomFunctionName(readTableFunction);
idocReadItem.AddCriteria(criteria);
idocReadItem.Run();
dtIdocItem = idocReadItem.Result;
}
if (dtIdocItem.Rows.Count == 0)
{
idocReadItem = new Utils.ReadTable(SystemName);
idocReadItem.TableName = "EDIDD_OLD";
idocReadItem.SetCustomFunctionName(readTableFunction);
idocReadItem.AddCriteria(criteria);
idocReadItem.Run();
dtIdocItem = idocReadItem.Result;
}
if (dtIdocItem.Rows.Count == 0)
{
throw new SAPException(String.Format("无法找到IDOC{0}明细", idocNumber));
}
//读取IDOC头
idocReadHeader = new Utils.ReadTable(SystemName);
idocReadHeader.TableName = "EDIDC";
idocReadHeader.SetCustomFunctionName(readTableFunction);
idocReadHeader.AddCriteria(criteria);
idocReadHeader.Run();
dtIdocHeder = idocReadHeader.Result;
if (dtIdocHeder.Rows.Count != 1)
{
throw new SAPException(String.Format("无法找到IDOC{0}抬头定义", idocNumber));
}
Idoc idoc = ProcessSingleIdocFromDataTable(dtIdocHeder, dtIdocItem);
return idoc;
}
示例4: AddResult
/* Ham AddResult muc dich de cong 2 chuoi tham so nguoi dung nhap vao
* su dung cau lenh CanAdd de kiem tra chuoi co hop le hay khong */
public String AddResult(String x, String y)
{
/*Dieu chinh lai sao cho 2 chuoi nhap vao co cung do dai
* nham de thuc hien phep cong, chuoi nao co do dai nho hon
* se duoc bo sung vao nhung con so 0 */
if (x.Length > y.Length)
{
y=y.PadLeft(x.Length, '0');
}
else
{
x=x.PadLeft(y.Length, '0');
}
bool remember = false;// Bien nho, neu bien nho la true thi phep cong truoc cho ra ket qua > 10
int ix, iy; // Bien int dung de cong, phai thuc hien thao tac chuyen doi tu kieu char sang int
String result = string.Empty;
for (int i = x.Length - 1; i >= 0; i--)
{
/* Chuyen doi sang kieu int:
* Theo bang ma ASCII thi giua '0' (kieu char) va so 0
* chenh lech nhau 48 don vi, vi vay de chuyen tu kieu char
* sang int ta lay kieu char tru di 48 don vi */
ix = x[i] - 48;
iy = y[i] - 48;
/*Cac thao tac cong nhu ta cong thu cong */
int value = ix + iy;
if (remember)
{
value += 1;
}
if (value >= 10)
{
result = result.Insert(0, (value - 10).ToString());
remember = true;
}
else
{
result = result.Insert(0, value.ToString());
remember = false;
}
}
if (remember)
{
result = result.Insert(0,"1");
}
return result;
}
示例5: generaCodigoMaquina
public void generaCodigoMaquina(baseNumerica contlocFile,CODOP codop,String contLocLabel)
{
baseNumerica contEtiqueta = new baseNumerica(contLocLabel);
baseNumerica contLocNext = new baseNumerica(System.Convert.ToString(contlocFile.getNumberDecimal() + codop.getBytesTotales()));
baseNumerica contLocNew = new baseNumerica("0");
fueraRango = false;
int valor = contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal();
if (valor < 0)
{
char[] caracteres = { '-' };
String tmp = System.Convert.ToString(valor);
tmp = tmp.TrimStart(caracteres);
contLocNew = new baseNumerica(tmp,1);
tmp = contLocNew.getNumberHexadecimal();
xb = "";
for (int i = (tmp.Length) - (2*codop.getBytesPorCalcular()); i<tmp.Length;i++ )
{
xb += tmp[i];
}
}
else
{
contLocNew = new baseNumerica(System.Convert.ToString(contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal()));
xb = contLocNew.getNumberHexadecimal();
xb = xb.PadLeft(2 * codop.getBytesPorCalcular(), '0');
}
if(codop.getBytesPorCalcular() == 1)
{
if (!(contLocNew.getNumberDecimal() >= -128 && contLocNew.getNumberDecimal() <= 127))
{
fueraRango = true;
}
}
else
{
if (!(contLocNew.getNumberDecimal() >= -32768 && contLocNew.getNumberDecimal() <= 32767))
{
fueraRango = true;
}
}
}
示例6: PrepareString
protected String PrepareString(String s)
{
if(s == null)
{
s = _emptyString;
}
else if(s.Length > _arrayLength)
{
Console.Error.WriteLine("Warning: String value too wide for column; truncating.");
if(_trimLeft)
{
s = s.Substring(s.Length - _arrayLength, _arrayLength);
}
else
{
s = s.Substring(0, _arrayLength);
}
}
else if(s.Length < _arrayLength)
{
if(_padLeft)
{
s = s.PadLeft(_arrayLength, _padChar);
}
else
{
s = s.PadRight(_arrayLength, _padChar);
}
}
return s;
}
示例7: ValidarFormularioBloco
public static string ValidarFormularioBloco(String bloco)
{
if (bloco.Length == 1)
{
bloco = bloco.PadLeft(2, '0');
return bloco;
}
else
{
return bloco;
}
}
示例8: FillSpecifyWith0
/// <summary>
/// 数字型字符串右对齐,左补零
/// </summary>
/// <returns></returns>
public static String FillSpecifyWith0(String number, UInt16 width)
{
if (String.IsNullOrEmpty(number))
{
number = String.Empty;
}
if (number.Length > width)
{
return number.Substring(0, width);
}
else
{
return number.PadLeft(width, '0');
}
}
示例9: FillSpecifyWidthFigure
/// <summary>
/// 数字对齐补足
/// </summary>
/// <param name="src"></param>
/// <param name="width"></param>
/// <returns></returns>
public static String FillSpecifyWidthFigure(String src, UInt16 width)
{
if (String.IsNullOrEmpty(src))
{
return SpaceString(width);
}
if (src.Length > width)
{
return src.Substring(0, width);
}
else
{
return src.PadLeft(width);
}
}
示例10: Append
public Request Append(String data, Int32 exactLength, TextJustification justification)
{
if (data.Length > exactLength)
data = data.Substring(0, exactLength);
else
{
if (data.Length < exactLength)
{
switch (justification)
{
case TextJustification.Left:
data = data.PadRight(exactLength);
break;
case TextJustification.Center:
var spaces = new String(' ', (exactLength - data.Length) / 2);
data = String.Concat(spaces, data, spaces);
break;
default:
data = data.PadLeft(exactLength);
break;
}
}
}
return Append(data);
}
示例11: ReadColor
internal static Color ReadColor(XmlNode node, String prop, Color dval)
{
Color t = dval;
if (node != null)
{
XmlAttribute attr = node.Attributes[prop];
if (attr != null)
{
prop = (attr.Value ?? "").ToLower();
if (Regex.IsMatch(prop, "^[#]?[0123456789abcdef]{6,8}$"))
{
if (prop[0] == '#')
{
prop = prop.Substring(1);
}
if (prop.Length < 8)
{
prop = prop.PadLeft(8, 'f');
}
t = Color.FromArgb(Convert.ToInt32(prop, 16));
}
}
}
return t;
}
示例12: setLongitudCuerpo
public void setLongitudCuerpo(String longitudCuerpo)
{
char pad = '0';
this.longitudCuerpo = longitudCuerpo.PadLeft(4, pad);
}
示例13: CreateRequest
private byte[] CreateRequest(String terminalNo, int messageType, Command cmd, byte[] data, int dataLen)
{
/* General Message for Request
* XX Length
* ASCII Terminal Serial
* XX Message Type
* BCD SequenceNum
* BCD Date
* BCD Time
* [Detail]
* XX LRC
*/
Encoding encode = Encoding.GetEncoding(1254);
List<byte> reqPacket = new List<byte>();
List<byte> msgPacket = new List<byte>();
int allLen = dataLen;
this.command = cmd;
this.data = data;
this.sequence = (MainForm.SequenceNumber++) % MAX_PRCSS_SEC_NUM;
//SEQUNCE
reqPacket.AddRange(MessageBuilder.HexToByteArray(GMPCommonTags.TAG_SEQUNCE));
reqPacket.Add((byte)GMPConstants.LEN_SEQUENCE);
byte[] arrVal = MessageBuilder.ConvertIntToBCD(this.Sequence, GMPConstants.LEN_SEQUENCE);
reqPacket.AddRange(arrVal);
//DATE and TIME
reqPacket.AddRange(MessageBuilder.GetDateTimeInBytes(DateTime.Now));
// Fiscal Command
if (cmd != Command.NULL)
{
reqPacket.AddRange(MessageBuilder.HexToByteArray(FPUCommonTags.FPU_FISCAL_COMMAND));
reqPacket.Add((byte)GMPConstants.LEN_FISCAL_COMMAND);
reqPacket.Add((byte)cmd);
}
if (dataLen > 0)
{
reqPacket.AddRange(data);
}
// Terminal ID
msgPacket.AddRange(encode.GetBytes(terminalNo.PadLeft(12, ' ')));
// Message TAG
msgPacket.AddRange(MessageBuilder.HexToByteArray(messageType));
// Message length
int msgLen = reqPacket.Count;
msgPacket.AddRange(MessageBuilder.AddLength(msgLen));
// Message Data
msgPacket.AddRange(reqPacket);
// CRC
short crc = MessageBuilder.CalculateCRC(msgPacket.ToArray(), 0, msgPacket.Count);
msgPacket.Add((byte)(crc >> 8));
msgPacket.Add((byte)(crc));
// All Length
allLen = msgPacket.Count;
msgPacket.Insert(0, (byte)(allLen % 256));
msgPacket.Insert(0, (byte)(allLen / 256));
return msgPacket.ToArray();
}
示例14: SetSocialNumber
/// <summary>
/// Mutator for socialinsuranceNumber.
/// </summary>
/// <param name="socialInsNum">Value for socialInsuranceNumber</param>
/// <returns>A boolean value indicating whether or not the parameter was valid.</returns>
public bool SetSocialNumber(String socialInsNum)
{
if (CheckSinNumber(socialInsNum) == false)
{
logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'T', 'F', socialInsNum);
return false;
}
else
{
socialInsNum = socialInsNum.PadLeft(9, '0');
this.socialInsuranceNumber = socialInsNum;
logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'T', 'S', socialInsNum);
}
return true;
}
示例15: CheckSinNumber
/// <summary>
/// Validates a SIN number. Uses method from http://www.ryerson.ca/JavaScript/lectures/forms/textValidation/sinProject.html
/// </summary>
/// <param name="sinNumber">The SIN number to be validated.</param>
/// <returns>A boolean value indicating whether or not the SIN Number is valid.</returns>
public virtual bool CheckSinNumber(String sinNumber)
{
int[] sinNumbers = new int[9];
int total = 0;
int temp = 0;
sinNumber = sinNumber.Replace(" ", "");
if (sinNumber.Length <= 9)
{
String tempString = sinNumber.PadLeft(9, '0');
for (int i = 0; i < tempString.Length; i++)
{
sinNumbers[i] = (int)Char.GetNumericValue(tempString[i]);
}
sinNumbers[1] = sinNumbers[1] * 2;
sinNumbers[3] = sinNumbers[3] * 2;
sinNumbers[5] = sinNumbers[5] * 2;
sinNumbers[7] = sinNumbers[7] * 2;
total += (sinNumbers[1] / 10);
total += (sinNumbers[1] % 10);
total += (sinNumbers[3] / 10);
total += (sinNumbers[3] % 10);
total += (sinNumbers[5] / 10);
total += (sinNumbers[5] % 10);
total += (sinNumbers[7] / 10);
total += (sinNumbers[7] % 10);
total += sinNumbers[0] + sinNumbers[2] + sinNumbers[4] + sinNumbers[6];
if (total % 10 == 0)
{
if (sinNumbers[8] == 0)
{
return true;
}
}
else
{
temp = ((total / 10) + 1) * 10;
total = temp - total;
if (total == sinNumbers[8])
{
return true;
}
}
}
return false;
}