0

I have a string

"vtn:o:result:/buffer/get/"

I want to replace character "o" with "b" So that resultant string is

"vtn:b:result:/buffer/get/"

I am trying following method:

var alphabet = "vtn:o:result:/buffer/get/";
alphabet = alphabet.replace(/:o.*:/, 'b');

But not getting the required result. I don't want to use jQuery, just JavaScript.

1
  • Why not just = alphabet.replace(':o:', ':b:'); Commented Jan 6, 2015 at 12:24

1 Answer 1

1

You should be able to do

 alphabet.replace('o', 'b');
Sign up to request clarification or add additional context in comments.

4 Comments

It will replace every o in string. I am assuming that /buffer/get/ can be /boffer/get, then this o will also be replaced i want to replace only o which are in between two colons
replace(':o:', ':b:');
@VarunChadha: No, it won't replace every o in the string, it will only replace the first.
if i have string "von:o:result:/buffer/get/", then resultant string will be "vbn:o:result:/buffer/get/", which is not expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.