我在DB中的一列中存储了ASCII小数点的字符串:
[104 105]
这将转换为 hi
。
我需要能够将我的列转换为字符串表示。
我知道我可以使用 string.fromcharcode(num,... num+1)
,但这对我不太有用。
我需要解析并将我的DB列值 [104 105]
分为两个单独的vars:
var num1 = 104;
var num2 - 105;
当我具有复杂的ASCII小数表示时,这无效。
是否有更有效的方法可以做到这一点?我的输入将是 [104 105 243 0 0 0 255 ...]
,它是ASCII小数点的,我需要获得字符串表示。
I have a string in representation of ASCII decimal stored in a column in my db:
[104 105]
this converts to hi
.
I need to be able to convert my column into string representation.
I know I can use String.fromCharCode(num,...num+1)
but it doesn't quite work for me.
I would need to parse and split my db column value [104 105]
into two separate vars:
var num1 = 104;
var num2 - 105;
this doesn't work when I have a complex ASCII decimal representation.
Is there a more efficient way to do this? My input would be something like [104 105 243 0 0 255...]
which is in ASCII decimal and I need to get the string representation.
发布评论
评论(2)
您需要首先解析该字符串,通过删除
[]
字符,在空格上拆分并将数组元素转换为数字。You need to parse that string first, by removing the
[]
characters, splitting at spaces, and converting the array elements to numbers.您可以使用 带有正则,然后
地图
并返回转换的代码的数组。只是在末尾将数组成弦。You can find the codes using
match
with a regex, and thenmap
and return an array of the converted codes. Justjoin
the array into a string at the end.