By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

Removing return characters from a string

bugboy
100+
P: 160
Hi, I need to remove the return characters from a string but i can't figure out how to reference it in a replace() method.

Expand|Select|Wrap|Line Numbers
  1. this.value=this.value.replace(/char(13)/, "");
Also when i test the code by replacing the letter /a/ it only replaces the first instance of it.. how do i get it to replace them all?

Thanks!
May 21 '09 #1
Share this Question
Share on Google+
4 Replies


P: 28
try to put the global match into your RegEx.

this.value.replace(/a*/g, "");
May 21 '09 #2

bugboy
100+
P: 160
Thanks! as it turns out /a*/g can just be /a/g if you want to replace 'a' with a different character... otherwise it add the new char after every letter.

this.value=this.value.replace(/a/g, "");
May 21 '09 #3

bugboy
100+
P: 160
Also a 'return' is a 'new line' so it's accessed via \n

this.value=this.value.replace(/\n/g, "");
May 21 '09 #4

bugboy
100+
P: 160
Thanks for the help guys!
May 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.