Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16124

Re: indexOf fails to find the first letter in a string

From Dr J R Stockton <reply1237@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: indexOf fails to find the first letter in a string
Date 2012-09-22 19:18 +0100
Organization Home
Message-ID <RymLVnD9DgXQFwi1@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <7c3f6696-0634-4b17-9ac6-720ca1572e9d@i14g2000yqo.googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <7c3f6696-0634-4b17-9ac6-720ca1572e9d@i1
4g2000yqo.googlegroups.com>, Thu, 20 Sep 2012 16:25:08, justaguy
<lichunshen84@gmail.com> posted:

>var str = "$100";
>// it would work if we declare the var as
>// var str = "100$" but no one writes English like that :)
>if (str.IndexOf('$')) {
>  alert("Please remove the $ sign");
>  return false;
>}
>
>What's the correct syntax to do it?  Thanks.


var str = "100";
//  "100$" but no one writes English like that // false comment
if (/\$/.test(str)) {
  alert("Please remove the $ sign");
  // return false;  // not in a function at present
  }


-- 
 (c) John Stockton, nr London, UK.  Mail via homepage.  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
 No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

indexOf fails to find the first letter in a string justaguy <lichunshen84@gmail.com> - 2012-09-20 16:25 -0700
  Re: indexOf fails to find the first letter in a string "S.T." <anon@anon.com> - 2012-09-20 17:16 -0700
    Re: indexOf fails to find the first letter in a string justaguy <lichunshen84@gmail.com> - 2012-09-20 18:42 -0700
  Re: indexOf fails to find the first letter in a string Scott Sauyet <scott.sauyet@gmail.com> - 2012-09-20 17:32 -0700
    Re: indexOf fails to find the first letter in a string justaguy <lichunshen84@gmail.com> - 2012-09-20 18:42 -0700
  Re: indexOf fails to find the first letter in a string Dr J R Stockton <reply1237@merlyn.demon.co.uk.invalid> - 2012-09-22 19:18 +0100

csiph-web