কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে বাফারকে পাঠযোগ্য স্ট্রিং-এ রূপান্তর করুন


এজন্য toString('utf8') কনসেপ্ট ব্যবহার করুন। নিচের কোডটি দেখুন −

নিচের কোডে বাফারের বিস্তারিত ব্যাখ্যা দেওয়া আছে।

উদাহরণ

var actualBufferObject = Buffer.from('[John Smith]', 'utf8') console.log("The actual buffer object="); console.log(JSON.stringify(actualBufferObject)) console.log("Get back the original object="); console.log(actualBufferObject.toString('utf8')); var myObjectValue = '[John Smith]'; console.log("The data you are getting from the buffer is equal to ASCII code equivalent...") for (var counter = 0; counter < myObjectValue.length; counter++) {    console.log("The ascii value of " + myObjectValue[counter] + " is ="    + (myObjectValue.charCodeAt(counter))); }

উপরোক্ত প্রোগ্রাম চালাতে নিচের কমান্ডটি ব্যবহার করুন −

node fileName.js.

এখানে, আমার ফাইলটির নাম demo197.js।

আউটপুট

এটি নিচের আউটপুট তৈরি করবে −

PS C:\Users\Amit\javascript-code> node demo197.js The actual buffer object= {"type":"Buffer","data":[91,74,111,104,110,32,83,109,105,116,104,93]} Get back the original object= [John Smith] The data you are getting from the buffer is equal to ASCII code equivalent... The ascii value of [ is =91 The ascii value of J is =74 The ascii value of o is =111 The ascii value of h is =104 The ascii value of n is =110 The ascii value of is =32 The ascii value of S is =83 The ascii value of m is =109 The ascii value of i is =105 The ascii value of t is =116 The ascii value of h is =104 The ascii value of ] is =93

  1. জাভাস্ক্রিপ্ট দিয়ে স্ট্রিং বুলিয়ানে রূপান্তর করা

  2. স্ট্রিংকে জাভাস্ক্রিপ্ট অবজেক্টে রূপান্তর করা

  3. জাভাস্ক্রিপ্টে ইন্টিজার অ্যারেকে স্ট্রিং অ্যারেতে রূপান্তর করা

  4. C++-এ হেক্সাডেসিমেল ভ্যালু স্ট্রিংকে ASCII ভ্যালু স্ট্রিংয়ে রূপান্তর করা