-3

I have a quick question

I have string var str="0-12345";

How can I actually remove the dash from the string if there is one in Javascript .. How can I check if a string has a dash , and if it has , remove the dash from it ?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Rogers
  • 2,905
  • 3
  • 14
  • 11
  • please do a bit of research before asking a question, check here for an answer to similar question:http://stackoverflow.com/questions/10060804/how-to-check-if-string-contains-character – razz Mar 26 '13 at 00:46
  • @razzak: Java is not JavaScript ;) – Felix Kling Mar 26 '13 at 00:59
  • my mistake i havent checked actually if the link was for java or javascript, even though it's for java the `string.indexOf("character") != -1` will work on both languages, `contains()` however wont work in javascript. – razz Mar 26 '13 at 01:14

1 Answers1

0

you have forgot to do the homework before you asked here , any way

var str="0-12345";
var is_dashed=(str.indexOf("-") !== -1);
str= str.replace('-',''); //many more ideas , it seems simple to remove all '-'
internals-in
  • 4,798
  • 2
  • 21
  • 38