ধরি আমাদের নিচের স্ট্রিংটি আছে:
var sentence = "My Name is David Miller I live in AUS";
উপরের স্ট্রিংতে থাকা স্পেসগুলো আন্ডারস্কোর (_) দিয়ে প্রতিস্থাপন করতে split() এবং join() মেথড ব্যবহার করা হয়।
উদাহরণ
নিচের কোডটি অনুসরণ করুন:
var sentence = "My Name is David Miller I live in AUS";
var withUnderscore = sentence.split(' ').join('_');
console.log("The actual result=");
console.log(sentence);
console.log("After replacing the space with underscore=");
console.log(withUnderscore);
প্রোগ্রামটি রান করতে নিচের কমান্ডটি ব্যবহার করুন:
node fileName.js
এখানে ফাইলের নাম হলো demo250.js।
আউটপুট
কনসোলে নিচের আউটপুটটি দেখাবে:
PS C:\Users\Amit\javascript-code> node demo250.js The actual result= My Name is David Miller I live in AUS After replacing the space with underscore= My_Name_is_David_Miller_I_live_in_AUS