nickyvetos / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

"In text...find" block returns 1 when second text is empty #145

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add a print block
2. Add a in text...find block
3. First text: "abcde"
4. Second text: "" (empty)
5. Run

What is the expected output? 0
What do you see instead? 1
What browser are you using? (Chrome, Firefox)

Original issue reported on code.google.com by azoun...@gmail.com on 11 May 2013 at 6:40

GoogleCodeExporter commented 8 years ago
The above happens when "first occurrence" is selected.
If "last occurrence" selected, it returns string.length+1.

Original comment by azoun...@gmail.com on 11 May 2013 at 6:44

GoogleCodeExporter commented 8 years ago
That's expected.  Try the following in JS:
  "abc".indexOf("")
or Python:
  "abc".find("")
Both return 0 (match on first character), not -1 (no match).

Blockly is a one-based language (like Lua or LambdaMOO), so the first character 
is 1.  Thus it is correct.

Original comment by neil.fra...@gmail.com on 20 May 2013 at 6:38

GoogleCodeExporter commented 8 years ago
You are perfectly correct as a programmer, but it feels a bit strange to teach 
that "nothing matches anything"...

Original comment by azoun...@gmail.com on 20 May 2013 at 10:16