GUID 格式化
2007-08-25 23:20 晓风残月 阅读(2541) 评论(3) 编辑 收藏 举报
System.Guid.ToString() 默认的输出方式是带 - (连字符)的,如果希望是单纯数字(16进制)呢?直观方法当然是 Replace 了,事实上 Guid 内置支持格式化:
Guid.ToString 方法 (String)
![](/Images/OutliningIndicators/None.gif)
public string ToString (
string format
)
![](/Images/OutliningIndicators/None.gif)
参数
format
一个单格式说明符,它指示如何格式化此 Guid 的值。format 参数可以是“N”、“D”、“B”或“P”。如果 format 为 空引用(在 Visual Basic 中为 Nothing) 或空字符串 (""),则使用“D”。
![](/Images/OutliningIndicators/None.gif)
返回值
此 Guid 值的 String 表示形式。
format 参数可以包含以下格式说明符。在下表中,返回值中的所有数字位均为十六进制。每个“x”字符表示一个十六进制位,每个连字符(“-”)、大括号(“{”、“}”)和圆括号(“(”、“)”)如表中所示。
![](/Images/OutliningIndicators/None.gif)
说明符
返回值的格式
N
32 位:
![](/Images/OutliningIndicators/None.gif)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
D
由连字符分隔的 32 位数字:
![](/Images/OutliningIndicators/None.gif)
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
B
括在大括号中、由连字符分隔的 32 位数字:
![](/Images/OutliningIndicators/None.gif)
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
P
括在圆括号中、由连字符分隔的 32 位数字:
![](/Images/OutliningIndicators/None.gif)
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
http://msdn2.microsoft.com/zh-cn/library/system.guid.tostring.aspx
注:此格式化参数不区分大小写。
问题来源:
我生成一个GUID 号 类似:4ae9fdeb-c19f-49f0-9678-0f4917a47d09
![](/Images/OutliningIndicators/None.gif)
怎样才能去除中间的破折号 “-”成为:4ae9fdebc19f49f096780f4917a47d09
![](/Images/OutliningIndicators/None.gif)
我想过用正则表达式,,但没弄成功,请问该怎么做?
http://community.csdn.net/Expert/TopicView3.asp?id=5728596
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
http://msdn2.microsoft.com/zh-cn/library/system.guid.tostring.aspx
注:此格式化参数不区分大小写。
问题来源:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)