Scratch-vm: Case detect block

Created on 18 Apr 2017  路  6Comments  路  Source: LLK/scratch-vm

Right now, the only ways to detect case are slow or require hacks (which should be creatable in the editor, but that's another story). A case detection block (like <[x] is uppercase?>/<[x] is lowercase?>) would be a fast and intuitive way to detect case.

request

Most helpful comment

Maybe also a block to convert to upper/lower case?

Also, how would this handle multi-letter strings? Would <[Foo] is uppercase?> check if it's all uppercase or contains any uppercase letters (or only check the first letter?). It might work better to do <letter (1) of [Foo] is uppercase?> to avoid those kinds of ambiguities

All 6 comments

Maybe it can be a dropdown for lowercase or uppercase.. make it simpler

Maybe also a block to convert to upper/lower case?

Also, how would this handle multi-letter strings? Would <[Foo] is uppercase?> check if it's all uppercase or contains any uppercase letters (or only check the first letter?). It might work better to do <letter (1) of [Foo] is uppercase?> to avoid those kinds of ambiguities

Maybe it should just be an all letters check. I think <letter (1) of [Foo] is uppercase?> is too long and clunky (it's just (letter (1) of [Foo])+<[F] is uppercase>. Plus making it a multi-letter check moves the check loop to Javascript (or maybe even native code, depending on implementation) instead of being in Scratch, which would be much slower.

Of course, having a basic ascii reporter would also be an option... One that returns the ascii value of the first character of the string? (or should it be unicode grin). I suppose uppercase is more generic, but perhaps is less useful that ascii. Ok, lets just have an (ascii value of [Foo]) please :)

See my String Manipulation Blocks project for a set of blocks that include case-detection, and a lot more besides, and are worded more precisely/clearly.

Combining (the most useful of) these into the dropdown of a <(string) contains [options v]> block would provide lots of flexibility, and it's a block that is almost the same as the new one that already exists in Scratch 3 (i.e. <(string) contains (substring)>), so can go after it in the block palette.

Possible menu items with Log's suggestion:

<(string) contains [uppercase v]>

<(string) contains [lowercase v]>

<(string) contains [letters v]>

<(string) contains [numbers v]>

Was this page helpful?
0 / 5 - 0 ratings