Guid和Oracle中16进制字符的转换
我们知道在Oracle中存的guid是16进制字符串,而在我们的C#代码中存的是guid对象,这样我会就要进行转换,
下面给出了两者进行转换的方法:
public class Guid2RawProcess { /// <summary> /// 转换 成16进制字符 /// </summary> /// <param name="text">The text.</param> /// <returns>System.String.</returns> static public string DotNet2Oracle(string text) { Guid guid = new Guid(text); return BitConverter.ToString(guid.ToByteArray()).Replace("-", ""); } /// <summary> ///16进制 转换成.net guid /// </summary> /// <param name="text">The text.</param> /// <returns>System.String.</returns> static public string Oracle2DotNet(string text) { byte[] bytes = ParseHex(text); Guid guid = new Guid(bytes); return guid.ToString().ToUpperInvariant(); } /// <summary> ///字符转换 /// </summary> /// <param name="text">The text.</param> /// <returns>System.Byte[][].</returns> static byte[] ParseHex(string text) { byte[] ret = new byte[text.Length / 2]; for (int i = 0; i < ret.Length; i++) { ret[i] = Convert.ToByte(text.Substring(i * 2, 2), 16); } return ret; } }