/// <example> /// Console.WriteLine(RowSource.PadLeftH("a한b", 2, 'x')); //xa /// Console.WriteLine(RowSource.PadLeftH("한글", 2, 'x')); //한 /// </example> public static string PadLeftH(string Value, int TotalWidth, char PaddingChar) { int LenH = CTwoByte.LenH(Value); if (LenH > TotalWidth) { int ModIs; Value = CTwoByte.LeftH(Value, TotalWidth, out ModIs); LenH = CTwoByte.LenH(Value); } int nPad = TotalWidth - LenH; return(CFindRep.Repeat(PaddingChar, nPad) + Value); }
public static string EncryptNumber(long Decrypted) { int[] aKey = GetKeyForEncryptNumber(); int Antilog = GetAntilogForEncryptNumber(); string sDecrypted = Decrypted.ToString(CFindRep.Repeat('0', aKey.Length)); string[] aDecrypted = CArray.SplitByLength(sDecrypted, 1); for (int i = 0; i < aDecrypted.Length; i++) { aDecrypted[i] = CMath.GetNFrom10((Convert.ToInt32(aDecrypted[i]) ^ aKey[i % 10]), Antilog); } return(string.Join("", aDecrypted)); }
/// <summary> /// 가운데 정렬 후 양쪽에 <paramref name="PaddingChar"/>를 채워서 <paramref name="TotalWidth"/> 길이를 맞춤. /// </summary> /// <param name="Value"></param> /// <param name="TotalWidth"></param> /// <param name="PaddingChar"></param> /// <returns></returns> /// <example> /// string s = CTwoByte.PadCenterH("안a녕", 8, 'x'); //"x안a녕xx" /// string s2 = CTwoByte.PadCenterH("12", 1, 'x'); //"12" /// string s3 = CTwoByte.PadCenterH("12", 3, 'x'); //"12x" /// </example> public static string PadCenterH(string Value, int TotalWidth, char PaddingChar) { int LenH = CTwoByte.LenH(Value); if (TotalWidth <= LenH) { return(Value); } int Half = (int)((TotalWidth - LenH) / 2); int Mod = (TotalWidth - LenH) % 2; if (Half == 0) { return(Value + CFindRep.Repeat(PaddingChar, Mod)); } string Pad = CFindRep.Repeat(PaddingChar, Half); return(Pad + Value + Pad + CFindRep.Repeat(PaddingChar, Mod)); }
private static string ConvertToJavaScript(Type T, int Depth) { string TmpAll = ""; if (Depth == 0) { TmpAll = @"var {{Name}} = { {{NameValue}} };"; } else { TmpAll = @", {{Tab}}{{Name}}: {{Tab}}{ {{NameValue}} {{Tab}}}"; } string TmpNameValue = ",\r\n{{Tab}}\t{{Name}}: {{Value}}"; string NameValue = ""; MemberInfo[] aMi = T.GetMembers(BindingFlags.Public | BindingFlags.Static); foreach (MemberInfo mi in aMi) { if (mi.MemberType == MemberTypes.Field) { FieldInfo fi = T.GetField(mi.Name); Type FieldType = fi.FieldType; string Name = fi.Name; string Value = ""; if (fi.IsLiteral) { object ConstValue = fi.GetRawConstantValue(); if (FieldType.IsEnum) { DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); string Desc = (attributes.Length > 0) ? attributes[0].Description : null; if (!string.IsNullOrEmpty(Desc)) { Value = string.Format("new CVnd(\"{0}\", \"{1}\", \"{2}\")", ConstValue, Name, Desc); } else { Value = ConstValue.ToString(); } } else { if (FieldType == typeof(char)) { Value = string.Format("'{0}'", ConstValue); } else if (FieldType == typeof(string)) { Value = string.Format("\"{0}\"", ConstValue); } else { Value = ConstValue.ToString(); } } } else if (fi.IsInitOnly) { if (FieldType == typeof(string[])) { string[] aValue = (string[])fi.GetValue(null); Value = "[ \"" + string.Join("\", \"", aValue) + "\" ]"; } } NameValue += TmpNameValue .Replace("{{Tab}}", CFindRep.Repeat('\t', Depth)) .Replace("{{Name}}", Name) .Replace("{{Value}}", Value.ToString()); } else if (mi.MemberType == MemberTypes.NestedType) { Type Typ = T.GetNestedType(mi.Name); NameValue += ConvertToJavaScript(Typ, Depth + 1); } } if (!string.IsNullOrEmpty(NameValue)) { NameValue = NameValue.Substring(",\r\n".Length); } string s = TmpAll .Replace("{{Tab}}", CFindRep.Repeat('\t', Depth)) .Replace("{{Name}}", T.Name) .Replace("{{NameValue}}", NameValue); return(s); }