She*_*eki 5 javascript php c# dicom angular
如何将 UUID/GUID 值8348d2c5-0a65-4560-bb24-f4f6bcba601d(我用uuid v4 进行分类)转换为 OID/DICOM UID 2.25.174506987738820548334170905323706671133?我更喜欢 JavaScript 的解决方案。请参阅维基百科)。
我用这个在线生成器转换的示例。
我知道您正在寻找 JavaScript 示例;但以下是 ac# 代码。看看是否可以将其翻译为 JavaScript。变量名称和数据类型是自我解释的,可以在翻译时帮助您。
下面的代码基于@VictorDerks 的答案。该答案中甚至解释了一种更快的方法;看一看。
public string GenerateUidFromGuid()
{
Guid guid = Guid.NewGuid();
string strTemp = "";
StringBuilder uid = new StringBuilder(64, 64);
uid.Append("2.25.");
//This code block is important------------------------------------------------
string guidBytes = string.Format("0{0:N}", guid);
BigInteger bigInteger = BigInteger.Parse(guidBytes, NumberStyles.HexNumber);
strTemp = string.Format(CultureInfo.InvariantCulture, "{0}", bigInteger);
uid.Append(strTemp);
//This code block is important------------------------------------------------
return uid.ToString();
}
Run Code Online (Sandbox Code Playgroud)
看起来Guid guid像f254934a-1cf5-47e7-913b-84431ba05b86。
回报。string.Format("0{0:N}", guid) 0f254934a1cf547e7913b84431ba05b86格式被删除并以零为前缀。
回报。BigInteger.Parse(guidBytes.... 322112315302124436275117686874389371782会将BigInteger.Parse字符串转换/解析为大整数数据类型。确定NumberStyles如何格式化。
基于@AmitJoshi 的其他答案;我现在可以回答我的问题了:
这是 JavaScript 函数:
function GenerateUidFromGuid(){
var guid = uuid.v4(); //Generate UUID using node-uuid *) package or some other similar package
var guidBytes = `0${guid.replace(/-/g, "")}`; //add prefix 0 and remove `-`
var bigInteger = bigInt(guidBytes,16); //As big integer are not still in all browser supported I use BigInteger **) packaged to parse the integer with base 16 from uuid string
return `2.25.${bigInteger.toString()}`; //Output the previus parsed integer as string by adding `2.25.` as prefix
}
Run Code Online (Sandbox Code Playgroud)
以下是参考资料:
| 归档时间: |
|
| 查看次数: |
3761 次 |
| 最近记录: |