Beispiel #1
0
        public static XmlDocument StrToXml(this Je.IStrExpander exp, string xml)
        {
            var doc = new XmlDocument();

            doc.LoadXml(xml);
            return(doc);
        }
Beispiel #2
0
        public static string Op(this Je.IStrExpander e, string fileName, string args)
        {
            var sb  = new StringBuilder();
            var psi = new ProcessStartInfo
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                StandardOutputEncoding = Encoding.GetEncoding(866)
            };

            psi.FileName  = fileName;
            psi.Arguments = args;
            var process = Process.Start(psi);

            while (process != null && !process.StandardOutput.EndOfStream)
            {
                sb.Append(process.StandardOutput.ReadLine());
            }
            if (process != null)
            {
                process.WaitForExit();
                process.Close();
            }
            var result = sb.ToString();

            return(result);
        }
Beispiel #3
0
        public static byte[] StrToBin(this Je.IStrExpander exp, string str, Encoding encoding = null)
        {
            var utf16 = Encoding.GetEncoding("utf-16");

            encoding = encoding ?? utf16;
            var bytes = utf16.GetBytes(str);

            if (encoding.EncodingName != utf16.EncodingName)
            {
                bytes = Encoding.Convert(utf16, encoding, bytes);
            }
            return(bytes);
        }
Beispiel #4
0
        public static string Reverse(this Je.IStrExpander e, string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return(s);
            }
            var sb = new StringBuilder();

            for (int i = s.Length - 1; i >= 0; i--)
            {
                sb.Append(s[i]);
            }
            return(sb.ToString());
        }
Beispiel #5
0
 public static string Right(this Je.IStrExpander e, string s, int length)
 {
     if (string.IsNullOrEmpty(s))
     {
         return(string.Empty);
     }
     if (length < 1)
     {
         return(string.Empty);
     }
     if (length > s.Length)
     {
         return(s);
     }
     return(s.Substring(s.Length - length));
 }
Beispiel #6
0
        public static string NewLen(this Je.IStrExpander exp, string s, int len)
        {
            s = s ?? string.Empty;
            var oldLen = s.Length;
            var newLen = len > 0 ? len : oldLen;

            if (newLen == oldLen)
            {
                return(s);
            }
            var sb = new StringBuilder();

            for (int i = 0; i < newLen; i++)
            {
                sb.Append(i < s.Length ? s[i] : ' ');
            }
            return(sb.ToString());
        }
Beispiel #7
0
 public static string Replace(this Je.IStrExpander e, string s, string substringOld, string substringNew)
 {
     if (substringOld == substringNew)
     {
         return(s);
     }
     if (substringOld == null)
     {
         return(s);
     }
     if (s == null)
     {
         return(null);
     }
     if (substringOld.Length > s.Length)
     {
         return(s);
     }
     substringNew = substringNew ?? "";
     return(s.Replace(substringOld, substringNew));
 }
Beispiel #8
0
        public static string Repeat(this Je.IStrExpander e, string s, int count)
        {
            if (s == null)
            {
                return(null);
            }
            if (s == string.Empty || count <= 0)
            {
                return(s);
            }
            if (count == 1)
            {
                return(s);
            }
            var sb = new StringBuilder();

            for (int i = 0; i < count; i++)
            {
                sb.Append(s);
            }
            return(sb.ToString());
        }
Beispiel #9
0
 public static TResult To <TResult, TConverter>(this Je.IStrExpander exp, string json) where TConverter : StringConverter
 {
     return((TResult)(Je.sys.InstanceOf <TConverter>()).Deserialize(json, typeof(TResult)));
 }
Beispiel #10
0
 public static T To <T>(this Je.IStrExpander exp, string json, StringConverter converter = null)
 {
     return((T)(converter ?? Converter).Deserialize(json, typeof(T)));
 }
Beispiel #11
0
 public static object To(this Je.IStrExpander e, string s, Type type, StringConverter converter = null)
 {
     return((converter ?? Converter).Deserialize(s, type));
 }
Beispiel #12
0
 public static string Of <TConverter>(this Je.IStrExpander e, object value) where TConverter : StringConverter
 {
     return((Je.sys.InstanceOf <TConverter>()).Serialize(value));
 }
Beispiel #13
0
 public static string Of(this Je.IStrExpander e, object value, StringConverter converter = null)
 {
     return((converter ?? Converter).Serialize(value));
 }