当前位置: 首页>>代码示例>>C#>>正文


C# String.IsNullOrWhiteSpace方法代码示例

本文整理汇总了C#中System.String.IsNullOrWhiteSpace方法的典型用法代码示例。如果您正苦于以下问题:C# String.IsNullOrWhiteSpace方法的具体用法?C# String.IsNullOrWhiteSpace怎么用?C# String.IsNullOrWhiteSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.String的用法示例。


在下文中一共展示了String.IsNullOrWhiteSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReleaseFolder

        /// <summary>释放文件夹</summary>
        /// <param name="asm"></param>
        /// <param name="prefix"></param>
        /// <param name="dest"></param>
        /// <param name="overWrite"></param>
        /// <param name="filenameResolver"></param>
        public static void ReleaseFolder(Assembly asm, String prefix, String dest, Boolean overWrite, Func<String, String> filenameResolver)
        {
            if (asm == null) asm = Assembly.GetCallingAssembly();

            // 找到符合条件的资源
            String[] names = asm.GetManifestResourceNames();
            if (names == null || names.Length < 1) return;
            IEnumerable<String> ns = null;
            if (prefix.IsNullOrWhiteSpace())
                ns = names.AsEnumerable();
            else
                ns = names.Where(e => e.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));

            if (String.IsNullOrEmpty(dest)) dest = AppDomain.CurrentDomain.BaseDirectory;

            if (!Path.IsPathRooted(dest))
            {
                String str = Runtime.IsWeb ? HttpRuntime.BinDirectory : AppDomain.CurrentDomain.BaseDirectory;
                dest = Path.Combine(str, dest);
            }

            // 开始处理
            foreach (String item in ns)
            {
                Stream stream = asm.GetManifestResourceStream(item);

                // 计算filename
                String filename = null;
                // 去掉前缀
                if (filenameResolver != null) filename = filenameResolver(item);

                if (String.IsNullOrEmpty(filename))
                {
                    filename = item;
                    if (!String.IsNullOrEmpty(prefix)) filename = filename.Substring(prefix.Length);
                    if (filename[0] == '.') filename = filename.Substring(1);

                    String ext = Path.GetExtension(item);
                    filename = filename.Substring(0, filename.Length - ext.Length);
                    filename = filename.Replace(".", @"\") + ext;
                    filename = Path.Combine(dest, filename);
                }

                if (File.Exists(filename) && !overWrite) return;

                String path = Path.GetDirectoryName(filename);
                if (!path.IsNullOrWhiteSpace() && !Directory.Exists(path)) Directory.CreateDirectory(path);
                try
                {
                    if (File.Exists(filename)) File.Delete(filename);

                    using (FileStream fs = File.Create(filename))
                    {
                        IOHelper.CopyTo(stream, fs);
                    }
                }
                catch { }
                finally { stream.Dispose(); }
            }
        }
开发者ID:g992com,项目名称:esb,代码行数:66,代码来源:FileSource.cs

示例2: DecodeFile

        /// <summary>
        /// Decrypt the encoded file and compare to original file. It returns false if the file is corrupted.
        /// </summary>
        /// <param name="key">The key used to encode the file</param>
        /// <param name="sourceFile">The file to decrypt complete path</param>
        /// <param name="destFile">Destination file complete path. If the file doesn't exist, it creates it</param>
        /// <returns></returns>
        public bool DecodeFile(string key, String sourceFile, String destFile)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");

            if (destFile.IsNullOrWhiteSpace())
                throw new ArgumentException("Please specify the path of the output path", nameof(destFile));

            if (string.IsNullOrEmpty(key))
                throw new ArgumentException("Please specify the key", nameof(key));

            // Create a key using a random number generator. This would be the
            //  secret key shared by sender and receiver.
            byte[] secretkey = key.ToByteArray();

            // Initialize the keyed hash object.
            HMACMD5 hmacMD5 = new HMACMD5(secretkey);
            // Create an array to hold the keyed hash value read from the file.
            byte[] storedHash = new byte[hmacMD5.HashSize / 8];
            // Create a FileStream for the source file.
            FileStream inStream = new FileStream(sourceFile, FileMode.Open);
            // Read in the storedHash.
            inStream.Read(storedHash, 0, storedHash.Length);
            // Compute the hash of the remaining contents of the file.
            // The stream is properly positioned at the beginning of the content,
            // immediately after the stored hash value.
            byte[] computedHash = hmacMD5.ComputeHash(inStream);
            // compare the computed hash with the stored value
            int i;
            for (i = 0; i < storedHash.Length; i++)
            {
                if (computedHash[i] != storedHash[i])
                {
                    inStream.Close();
                    return false;
                }
            }

            FileStream outStream = new FileStream(destFile, FileMode.Create);
            // Reset inStream to the beginning of the file.
            inStream.Position = i;
            // Copy the contents of the sourceFile to the destFile.
            int bytesRead;
            // read 1K at a time
            byte[] buffer = new byte[1024];
            do
            {
                // Read from the wrapping CryptoStream.
                bytesRead = inStream.Read(buffer, 0, 1024);
                outStream.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);
            // Close the streams
            inStream.Close();
            outStream.Close();
            return true;
        }
开发者ID:n3wt0n,项目名称:Crypto,代码行数:63,代码来源:HMACMD5.cs

示例3: DecodeString

 /// <summary>
 /// Decode a string encoded in Base64 format
 /// </summary>
 /// <param name="sourceString">The encoded string to decode</param>
 /// <returns>The decoded string</returns>
 public string DecodeString(String sourceString)
 {
     if (!sourceString.IsNullOrWhiteSpace())
     {
         byte[] filebytes = Convert.FromBase64String(sourceString);
         return Utils.ByteArrayToStr(filebytes);
     }
     else
         return string.Empty;
 }
开发者ID:n3wt0n,项目名称:Crypto,代码行数:15,代码来源:Base64.cs

示例4: EncodeString

 /// <summary>
 /// Encode a string using Base64 format
 /// </summary>
 /// <param name="sourceString">The source string to encode</param>
 /// <returns>The encoded string</returns>
 public string EncodeString(String sourceString)
 {
     if (!sourceString.IsNullOrWhiteSpace())
     {
         byte[] filebytes = sourceString.ToByteArray();
         return Convert.ToBase64String(filebytes);
     }
     else
         return string.Empty;
 }
开发者ID:n3wt0n,项目名称:Crypto,代码行数:15,代码来源:Base64.cs

示例5: AddTorrentFromData

        public void AddTorrentFromData(Byte[] torrentData, String downloadDirectory, TransmissionSettings settings)
        {
            var arguments = new Dictionary<String, Object>();
            arguments.Add("metainfo", Convert.ToBase64String(torrentData));

            if (!downloadDirectory.IsNullOrWhiteSpace())
            {
                arguments.Add("download-dir", downloadDirectory);
            }

            ProcessRequest("torrent-add", arguments, settings);
        }
开发者ID:nnic,项目名称:Sonarr,代码行数:12,代码来源:TransmissionProxy.cs

示例6: AddTorrentFromUrl

        public void AddTorrentFromUrl(String torrentUrl, String downloadDirectory, TransmissionSettings settings)
        {
            var arguments = new Dictionary<String, Object>();
            arguments.Add("filename", torrentUrl);

            if (!downloadDirectory.IsNullOrWhiteSpace())
            {
                arguments.Add("download-dir", downloadDirectory);
            }

            ProcessRequest("torrent-add", arguments, settings);
        }
开发者ID:nnic,项目名称:Sonarr,代码行数:12,代码来源:TransmissionProxy.cs

示例7: DecodeFile

        /// <summary>
        /// Decode a File encoded in Base64 format
        /// </summary>
        /// <param name="sourceFile">The file to decrypt complete path</param>
        /// <param name="destFile">Destination file complete path. If the file doesn't exist, it creates it</param>
        public void DecodeFile(String sourceFile, String destFile)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");

            if (destFile.IsNullOrWhiteSpace())
                throw new ArgumentException("Please specify the path of the output path", nameof(destFile));

            string input = File.ReadAllText(sourceFile);
            byte[] filebytes = Convert.FromBase64String(input);
            FileStream fs = new FileStream(destFile, FileMode.Create, FileAccess.Write, FileShare.None);
            fs.Write(filebytes, 0, filebytes.Length);
            fs.Close();
        }
开发者ID:n3wt0n,项目名称:Crypto,代码行数:19,代码来源:Base64.cs

示例8: EncodeFile

        /// <summary>
        /// Encode a File using Base64 format
        /// </summary>
        /// <param name="sourceFile">The file to encrypt complete path</param>
        /// <param name="destFile">Destination file complete path. If the file doesn't exist, it creates it</param>
        public void EncodeFile(String sourceFile, String destFile)
        {
            if (sourceFile.IsNullOrWhiteSpace() || !File.Exists(sourceFile))
                throw new FileNotFoundException("Cannot find the specified source file", sourceFile ?? "null");

            if (destFile.IsNullOrWhiteSpace())
                throw new ArgumentException("Please specify the path of the output path", nameof(destFile));

            using (var fs = new BufferedStream(File.OpenRead(sourceFile), 1200000))
            {
                byte[] filebytes = new byte[fs.Length];
                fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
                string encodedData = Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks);
                File.WriteAllText(destFile, encodedData);
            }
        }
开发者ID:n3wt0n,项目名称:Crypto,代码行数:21,代码来源:Base64.cs

示例9: TryGetMessageBusType

        /// <summary>
        /// Gets a message bus type based on the specified string <paramref name="value"/>.
        /// </summary>
        /// <param name="value">The value to convert to an message bus type (i.e., name, value or unique description).</param>
        /// <param name="result">The message bus type.</param>
        public static Boolean TryGetMessageBusType(String value, out MessageBusType result)
        {
            Int32 parsedValue;
            Object boxedValue = Int32.TryParse(value, out parsedValue) ? parsedValue : (Object)value;

            if (value.IsNullOrWhiteSpace())
            {
                result = MessageBusType.MicrosoftMessageQueuing;
                return true;
            }

            if (Enum.IsDefined(typeof(MessageBusType), boxedValue))
            {
                result = (MessageBusType)Enum.ToObject(typeof(MessageBusType), boxedValue);
                return true;
            }

            return KnownMessageBusTypes.TryGetValue(value, out result);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:24,代码来源:Program.cs

示例10: FileNameStr

        /// <summary>工具方法:生成年月日时分秒字符串</summary>
        /// <param name="link">年月日时分秒之间的连接字符</param>
        /// <param name="RanLength">最后生成随机数的位数</param>
        /// <returns>返回年月日时分秒毫秒四位随机数字的字符串</returns>
        public static String FileNameStr(String link, Int32 RanLength)
        {
            if (link.IsNullOrWhiteSpace())
            {
                link = "";
            }
            Int32 Year = DateTime.Now.Year;            //年
            Int32 Month = DateTime.Now.Month;          //月份
            Int32 Day = DateTime.Now.Day;              //日期
            Int32 Hour = DateTime.Now.Hour;            //小时
            Int32 Minute = DateTime.Now.Minute;        //分钟
            Int32 Second = DateTime.Now.Second;        //秒
            Int32 Milli = DateTime.Now.Millisecond;    //毫秒

            //生成随机数字
            String DataString = "0123456789";
            Random rnd = new Random();
            String rndstring = "";
            Int32 i = 1;

            while (i <= RanLength)
            {
                rndstring += DataString[rnd.Next(DataString.Length)];
                i++;
            }
            String FileNameStr = (Year + link + Month + link + Day + link + Hour + link + Minute + link + Second + link + Milli + link + rndstring).ToString();
            return FileNameStr;
        }
开发者ID:hillterry,项目名称:Jetso,代码行数:32,代码来源:DateTimeHelper.cs

示例11: UpdateLibrary

        public String UpdateLibrary(XbmcSettings settings, String path)
        {
            var request = new RestRequest();
            var parameters = new Dictionary<String, Object>();
            parameters.Add("directory", path);

            if (path.IsNullOrWhiteSpace())
            {
                parameters = null;
            }

            var response = ProcessRequest(request, settings, "VideoLibrary.Scan", parameters);

            return Json.Deserialize<XbmcJsonResult<String>>(response).Result;
        }
开发者ID:keep3r,项目名称:Sonarr,代码行数:15,代码来源:XbmcJsonApiProxy.cs

示例12: ArrangeAddressSet

        private void ArrangeAddressSet(AddressSet addressSet, String street, String postCode, String houseNumber, String apartmentNumber, String city)
        {
            GetWordsFromField(addressSet.wordComponents, city.PrepareString(WORDSTOREMOVE));
              GetWordsFromField(addressSet.wordComponents, street.PrepareString(WORDSTOREMOVE));

              if (!postCode.IsNullOrWhiteSpace())
              {
            String tempCode = postCode.GetOnlyDigits();
            if (tempCode.Length == 5)
            {
              addressSet.postalCodeComponent = tempCode.Substring(0, 2) + " " + tempCode.Substring(2, 3);
            }
              }
              if (!String.IsNullOrEmpty(houseNumber))
              {
            addressSet.houseNumberComponent = houseNumber.PrepareString();
              }
              if (!String.IsNullOrEmpty(apartmentNumber))
              {
            addressSet.apartmentNumberComponent = apartmentNumber.PrepareString();
              }
        }
开发者ID:johny1515,项目名称:Bank_REI,代码行数:22,代码来源:Matcher.cs

示例13: GetWordsFromField

 private void GetWordsFromField(List<String> set, String input)
 {
     if (!input.IsNullOrWhiteSpace())
       {
     if (input.Trim().Contains(" ") || input.Trim().Contains("-"))
     {
       String[] split = input.Split(new char[] {' ', '-'} ,StringSplitOptions.RemoveEmptyEntries);
       foreach (String piece in split)
       {
     if (!piece.IsNullOrWhiteSpace())
     {
       set.Add(piece);
     }
       }
     }
     else
     {
       set.Add(input);
     }
       }
 }
开发者ID:johny1515,项目名称:Bank_REI,代码行数:21,代码来源:Matcher.cs

示例14: Parse

        /// <summary>分析</summary>
        /// <param name="uri"></param>
        public NetUri Parse(String uri)
        {
            if (uri.IsNullOrWhiteSpace()) return this;

            // 分析协议
            var p = uri.IndexOf(Sep);
            if (p > 0)
            {
                Protocol = uri.Substring(0, p);
                uri = uri.Substring(p + Sep.Length);
            }

            // 分析端口
            p = uri.LastIndexOf(":");
            if (p >= 0)
            {
                var pt = uri.Substring(p + 1);
                Int32 port = 0;
                if (Int32.TryParse(pt, out port))
                {
                    Port = port;
                    uri = uri.Substring(0, p);
                }
            }

            Host = uri;

            return this;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:31,代码来源:NetUri.cs

示例15: Split

        /// <summary>拆分排序字句</summary>
        /// <param name="orderby"></param>
        /// <param name="isdescs"></param>
        /// <returns></returns>
        public static String[] Split(String orderby, out Boolean[] isdescs)
        {
            isdescs = null;
            if (orderby.IsNullOrWhiteSpace()) return null;
            //2014-01-04 Modify by Apex
            //处理order by带有函数的情况,避免分隔时将函数拆分导致错误
            foreach (Match match in Regex.Matches(orderby, @"\([^\)]*\)", RegexOptions.Singleline))
            {
                orderby = orderby.Replace(match.Value, match.Value.Replace(",", "★"));
            }
            String[] ss = orderby.Trim().Split(",");
            if (ss == null || ss.Length < 1) return null;

            String[] keys = new String[ss.Length];
            isdescs = new Boolean[ss.Length];

            for (int i = 0; i < ss.Length; i++)
            {
                String[] ss2 = ss[i].Trim().Split(' ');
                // 拆分名称和排序,不知道是否存在多余一个空格的情况
                if (ss2 != null && ss2.Length > 0)
                {
                    keys[i] = ss2[0].Replace("★", ",");
                    if (ss2.Length > 1 && ss2[1].EqualIgnoreCase("desc")) isdescs[i] = true;
                }
            }
            return keys;
        }
开发者ID:tommybiteme,项目名称:X,代码行数:32,代码来源:SelectBuilder.cs


注:本文中的System.String.IsNullOrWhiteSpace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。