Browse Source

添加string判断空方法(调用string.IsNullOrWhiteSpace方法),调整txt工具判断文件是否存在

yuzhengyang 7 years ago
parent
commit
c3f316c2ca

BIN
Fork.Net/.vs/Fork.Net/v15/Server/sqlite3/storage.ide


BIN
Fork.Net/.vs/Fork.Net/v15/sqlite3/storage.ide


+ 20 - 2
Fork.Net/Azylee.Utils/Azylee.Core/DataUtils/StringUtils/StringTool.cs

@@ -1,7 +1,7 @@
 //************************************************************************
 //      https://github.com/yuzhengyang
 //      author:     yuzhengyang
-//      date:       2017.10.12 - 2017.10.12
+//      date:       2017.10.12 - 2018.5.17
 //      desc:       字符串工具类
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
@@ -14,6 +14,24 @@ namespace Azylee.Core.DataUtils.StringUtils
     public sealed class StringTool
     {
         /// <summary>
+        /// 判断字符串 非null、""、空格(Not NullOrWhiteSpace)
+        /// </summary>
+        /// <param name="s"></param>
+        /// <returns></returns>
+        public static bool Ok(string s)
+        {
+            return !string.IsNullOrWhiteSpace(s);
+        }
+        /// <summary>
+        /// 判断字符串 非null、""(Not NullOrEmpty)
+        /// </summary>
+        /// <param name="s"></param>
+        /// <returns></returns>
+        public static bool Ok2(string s)
+        {
+            return !string.IsNullOrEmpty(s);
+        }
+        /// <summary>
         /// 判断字符串为null或为空格
         /// </summary>
         /// <param name="str"></param>
@@ -33,7 +51,7 @@ namespace Azylee.Core.DataUtils.StringUtils
         /// <param name="s"></param>
         /// <param name="word"></param>
         /// <returns></returns>
-        public static bool Contains(string s,string word)
+        public static bool Contains(string s, string word)
         {
             if (s.ToLower().Contains(word.ToLower()))
                 return true;

+ 9 - 6
Fork.Net/Azylee.Utils/Azylee.Core/IOUtils/TxtUtils/TxtTool.cs

@@ -61,15 +61,18 @@ namespace Azylee.Core.IOUtils.TxtUtils
         {
             try
             {
-                using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
+                if (File.Exists(file))
                 {
-                    string result = "", line;
-                    while ((line = sr.ReadLine()) != null)
-                        result += line.ToString();
-                    return result;
+                    using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
+                    {
+                        string result = "", line;
+                        while ((line = sr.ReadLine()) != null)
+                            result += line.ToString();
+                        return result;
+                    }
                 }
             }
-            catch (Exception e) { }
+            catch { }
             return null;
         }
         public static List<string> ReadLine(string file)