如何在没有Bom的情况下将字符串转换为UTF-8中的byteArray
how to convert string to byteArray in UTF-8 Without Bom
我将文本转换为 Base64 byteArray 没有任何问题。不幸的是,转换后的字符串需要以 "PD" 开头。这意味着我应该将它编码为不带 BOM 的 UTF-8,而不是带 BOM。我开始了几个代码和网上的一切。但是,我无法成功。任何帮助表示赞赏。
非常感谢。
问候
阿尔珀
public static byte[] convertToByteArray(String strToBeConverted) {
return strToBeConverted.getBytes(StandardCharsets.UTF_8);
}
return strToBeConverted.replaceFirst("^\uFEFF", "").getBytes(StandardCharsets.UTF_8);
BOM 是 Unicode 代码点 U+FEFF。
删除它意味着首先检查它是否确实存在。 String.replaceFirst
成本高,因为它使用正则表达式匹配,但在这里没问题。
我将文本转换为 Base64 byteArray 没有任何问题。不幸的是,转换后的字符串需要以 "PD" 开头。这意味着我应该将它编码为不带 BOM 的 UTF-8,而不是带 BOM。我开始了几个代码和网上的一切。但是,我无法成功。任何帮助表示赞赏。
非常感谢。
问候 阿尔珀
public static byte[] convertToByteArray(String strToBeConverted) {
return strToBeConverted.getBytes(StandardCharsets.UTF_8);
}
return strToBeConverted.replaceFirst("^\uFEFF", "").getBytes(StandardCharsets.UTF_8);
BOM 是 Unicode 代码点 U+FEFF。
删除它意味着首先检查它是否确实存在。 String.replaceFirst
成本高,因为它使用正则表达式匹配,但在这里没问题。