zoukankan      html  css  js  c++  java
  • c# string 转 GUID

    提供两种方法

    1.try...catch...

     1         /*
     2          * string TO guid 
     3          */
     4         private static bool ToGuid(string str)
     5         {
     6             Guid gv = new Guid();
     7             try
     8             {
     9                 gv = new Guid(str);
    10             }
    11             catch (Exception)
    12             {
    13 
    14             }
    15             if (gv != Guid.Empty)
    16             {
    17                 return true;
    18             }
    19             else
    20             {
    21                 return false;
    22             }
    23         }

    2.match匹配

     1         /*
     2          * string TO guid 
     3          */
     4         private static bool ToGuid(string str)
     5         {
     6             Match m = Regex.Match(str,@"^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$",RegexOptions.IgnoreCase);
     7             Guid gv = new Guid();
     8             if (m.Success)
     9             {
    10                 gv = new Guid(str);
    11             }
    12             if (gv != Guid.Empty)
    13             {
    14                 return true;
    15             }
    16             else
    17             {
    18                 return false;
    19             }
    20         }
  • 相关阅读:
    [BZOJ 2821] 作诗
    [P1084] 疫情控制
    [BZOJ 2243] 染色
    Session
    Jinja2 及 render_template 的深度用法
    request机制
    三件套
    初识flask
    mysql大法
    liunx命令大全
  • 原文地址:https://www.cnblogs.com/zk-zhou/p/6510642.html
Copyright © 2011-2022 走看看