0

I have a set of ascii characters :

68,101,97,108 

I want to convert this to a string :

Deal 

in java script

Im currently doing something like :

var value = "68,101,97,108"; var convertedValue = ""; for (var i = 0; i < value.length; i++) { convertedValue += String.fromCharCode(parseInt(value[i], 2)); } 

This returns a blank string

2
  • 1
    Not exactly related, but String.fromCharCode expects an Unicode value as arguments, not ASCII code. Commented Oct 15, 2014 at 14:20
  • @Teemu. Yes, it expects a Unicode/UTF-16 code-unit, one or two of which encode a codepoint. @lokoko Unicode is a superset of ASCII and maps the same integers (codepoints) to the same characters. UTF-16 encodes all of those in one code-unit. So, String.fromCharCode() has the effect that you think it does without actually doing what you think it does. Commented Oct 16, 2014 at 2:15

1 Answer 1

2

You could get array valueArray from value then you iterate on it

var value = "68,101,97,108"; var convertedValue = ""; valueArray = value.split(",") for (var i = 0; i < valueArray.length; i++) { convertedValue += String.fromCharCode(valueArray[i]); } alert(convertedValue);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.