如何轻松地将以下字符串转换为具有相应数值(即 a = 0、b = 1、c = 2 等)的整数数组:
String plaintext = "sallywenttotheseashoretocollectseashellsxx";
最佳答案
嗯,您提出的问题定义不明确,但您可以执行以下操作:
char[] chars = text.toCharArray();
int[] results = new int[text.length()];
for(int i = 0; i < text.length(); i++) {
//your poorly defined conversion
results[i] = someOperation(chars[i])
}
.
.
// a best guess at what this function would do
private static int someOperation(char c) {
return (c - 'a');
}
如果字母 a
映射到 0,那么字母 A
映射到什么?
关于Java - 如何将一串字母转换为具有相应数值的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25881355/