/// <summary> /// 将s转换为bytes(bytes长度为len[当len比s转换出来的bytes更少的时候,用更少那个]) /// </summary> public static byte[] ToBytes(this string self, int len, Encoding encoding = null) { var bb = new byte[len]; ByteUtil.ZeroBytes(bb); if (self.IsNullOrWhiteSpace()) { return(null); } var tBb = self.GetBytes(encoding); ByteUtil.BytesCopy(tBb, bb, Math.Min(len, tBb.Length)); return(bb); }