Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » String to Lowercase
- OmnipotentPotato
-
Scratcher
1000+ posts
String to Lowercase
I'm making a project where a program takes a string from the user and prints it. But, if the user types something like “Derp” it does not work but with “derp” it would work. It is because I am having the program switch to costumes of each letter and I only have lowercase letters.
What I want to do is make it so that I can turn a string into all lowercase. Thanks.
What I want to do is make it so that I can turn a string into all lowercase. Thanks.
- powercon5
-
Scratcher
1000+ posts
String to Lowercase
I do not get what you mean do you have a link I can see
- OmnipotentPotato
-
Scratcher
1000+ posts
String to Lowercase
I do not get what you mean do you have a link I can seeHere is a project with it, but it is not really the one that I am doing: http://scratch.mit.edu/projects/20167108/
As you can see if you type in something like “heLLO tHIS proGraM doEs NoT worK wITh CAPital letTTers” it glitches out all weird.
All that I need is a way to turn a variable like “Hello” into an all lowercase string like “hello.” Does that make more sense?
- powercon5
-
Scratcher
1000+ posts
String to Lowercase
oh ok i can have a lookI do not get what you mean do you have a link I can seeHere is a project with it, but it is not really the one that I am doing: http://scratch.mit.edu/projects/20167108/
As you can see if you type in something like “heLLO tHIS proGraM doEs NoT worK wITh CAPital letTTers” it glitches out all weird.
All that I need is a way to turn a variable like “Hello” into an all lowercase string like “hello.” Does that make more sense?
- powercon5
-
Scratcher
1000+ posts
String to Lowercase
ok so it not working because all the costumes in sprite 1 are lowercase (there names) so you could creat 2 of each costume (the letters)and call oneI do not get what you mean do you have a link I can seeHere is a project with it, but it is not really the one that I am doing: http://scratch.mit.edu/projects/20167108/
As you can see if you type in something like “heLLO tHIS proGraM doEs NoT worK wITh CAPital letTTers” it glitches out all weird.
All that I need is a way to turn a variable like “Hello” into an all lowercase string like “hello.” Does that make more sense?
lower and upper case
like 1 a and 2 A
- powercon5
-
Scratcher
1000+ posts
String to Lowercase
or make it so if =A make it aok so it not working because all the costumes in sprite 1 are lowercase (there names) so you could creat 2 of each costume (the letters)and call oneI do not get what you mean do you have a link I can seeHere is a project with it, but it is not really the one that I am doing: http://scratch.mit.edu/projects/20167108/
As you can see if you type in something like “heLLO tHIS proGraM doEs NoT worK wITh CAPital letTTers” it glitches out all weird.
All that I need is a way to turn a variable like “Hello” into an all lowercase string like “hello.” Does that make more sense?
lower and upper case
like 1 a and 2 A
both should work
- stickfiregames
-
Scratcher
1000+ posts
String to Lowercase
This should work to convert a string to lowercase, but unfortunately it would slow down because it has to go through each letter individually:
list: letters
a
b
c
d
e
f
etc
define convert (string) to lowercase // run without screen refresh
set [lowercase v] to []
set [position v] to [1]
repeat (length of (string))
if <[letters v] contains (letter (position) of (string))> // character is a letter
set [letter v] to [0]
repeat until <(item (letter) of [letters v]) = (letter (position) of (string))> // = block is not case sensitive
change [letter v] by (1)
end
set [lowercase v] to (join (lowercase) (item (letter) of [letters v]))
else // character is not a letter, no need to case-change
set [lowercase v] to (join (lowercase) (letter (position) of [string v]))
end
change [position v] by (1)
end
Last edited by stickfiregames (Nov. 8, 2014 19:57:47)
- Greatguy123
-
Scratcher
500+ posts
String to Lowercase
The problem is that in Scratch A = a is true. So you usually can't sense if a letter is capital or not. I would just type the message out into another variable using all lowercase. Then just use that.
- OmnipotentPotato
-
Scratcher
1000+ posts
String to Lowercase
The problem is that in Scratch A = a is true. So you usually can't sense if a letter is capital or not. I would just type the message out into another variable using all lowercase. Then just use that.

- hppavilion
-
Scratcher
100+ posts
String to Lowercase
I'm making a project where a program takes aProbably the best way would be something like this:
string from the user and prints it. But, if the user types something like “Derp” it does not work but with “derp” it would work. It is because I am having the program switch to costumes of each letter and I only have lowercase letters.
What I want to do is make it so that I can turn a string into all lowercase. Thanks.
First, you should probably have two read-only indexes (variables and lists that are just there because it's more efficient to keep the data there than using a million if-thens.) One variable and one list
Let's call them NoCaps (the variable) and Caps (the list), The value of Caps is “ABCDEFGHIJKLMNOPQRSTUVWXYZ”, where each letter is a different item (this could be done with a variable, which I would prefer, but it's so much easier like this.) NoCaps is “abcdefghijklmnopqrstuvwxyz”, just one string. The rest of the variables actually change. The remaining variables will be “Out,” the output, and “i(x),” a number of variables called i, i2, i3, etc. which are index numbers. You'll basically need this script:
define Lowercase(String)
set [i v] to [0]
set [Out v] to [0]
repeat (length of (String))
change [i v] by (1)
if <[Caps v] contains (letter (i) of (String))> then
set [i2 v] to [0]
repeat until <(item (i2) of [Caps v]) = (letter (i) of (String))>
change [i2 v] by (1)
end
set [Out v] to (join (Out) (letter (i2) of (NoCaps))
else
set [Out v] to (join (Out) (letter (i) of (String))
end
end
- qwertyyjiop
-
Scratcher
8 posts
String to Lowercase
That's very helpful but when I make that script, it always adds a 0 at the beginning of the var Out. What should I do?I'm making a project where a program takes aProbably the best way would be something like this:
string from the user and prints it. But, if the user types something like “Derp” it does not work but with “derp” it would work. It is because I am having the program switch to costumes of each letter and I only have lowercase letters.
What I want to do is make it so that I can turn a string into all lowercase. Thanks.
First, you should probably have two read-only indexes (variables and lists that are just there because it's more efficient to keep the data there than using a million if-thens.) One variable and one list
Let's call them NoCaps (the variable) and Caps (the list), The value of Caps is “ABCDEFGHIJKLMNOPQRSTUVWXYZ”, where each letter is a different item (this could be done with a variable, which I would prefer, but it's so much easier like this.) NoCaps is “abcdefghijklmnopqrstuvwxyz”, just one string. The rest of the variables actually change. The remaining variables will be “Out,” the output, and “i(x),” a number of variables called i, i2, i3, etc. which are index numbers. You'll basically need this script:define Lowercase(String)
set [i v] to [0]
set [Out v] to []
repeat (length of (String))
change [i v] by (1)
if <[Caps v] contains (letter (i) of (String))> then
set [i2 v] to [0]
repeat until <(item (i2) of [Caps v]) = (letter (i) of (String))>
change [i2 v] by (1)
end
set [Out v] to (join (Out) (letter (i2) of (NoCaps))
else
set [Out v] to (join (Out) (letter (i) of (String))
end
end
UPDATE: Nvm, there was just a little bug when writing the script. The corrected version is @above.
Last edited by qwertyyjiop (Aug. 12, 2015 12:12:08)
- Pepperoni505
-
Scratcher
100+ posts
String to Lowercase
Here: THIS will work:
define Lowercase [string1]It would also work with Lowercase to uppercase, if you change the lowercase alphabet to the uppercase alphabet.
set [Lowercase alphabet v] to [abcdefghijklmnopqrstuvwxyz]
set [Output v] to []
set [Tick v] to [0]
repeat (length of (string1)
change [Tick v] by [1]
set [Lettering v] to [1]
set [IsSet v] to [0]
repeat (length of (Lowercase alphabet)
if <(letter (Lettering) of (Lowercase alphabet)) = (letter (Tick) of (string1)>
set [Output v] to (join (Output) (letter (Lettering) of (Lowercase alphabet)
set [IsSet v] to [1]
change [Lettering v] by [1]
else
change [Lettering v] by [1]
if <(IsSet) = [0]>
set [Output v] to (join (Output) (letter (Tick) of (string1)))
Last edited by Pepperoni505 (Aug. 12, 2015 12:42:35)
- MrFluffyPenguins
-
Scratcher
1000+ posts
String to Lowercase
I have the same problem.
They should add a block like this:
They should add a block like this:
convert [EXAMPLE] into lowercase
- asivi
-
Scratcher
1000+ posts
String to Lowercase
I have the same problem.
They should add a block like this:convert [EXAMPLE] into lowercase
There is a forum(Suggestions) where you can suggest any Scratch improvement you would like.
Please do not revive old topics. Thanks.
- Charles12310
-
Scratcher
1000+ posts
String to Lowercase
I'm not sure if the user has already approved an answer or not, or if the user is inactive, so I will still answer the question if not.
define convert (string) into lowercase
set [lowercase letters v] to [abcdefghijklmnopqrstuvwxyz]
set [i v] to [0]
set [return v] to []
repeat (length of (string))
change [i v] by (1)
set [i2 v] to [0]
repeat until <(letter (i2) of (lowercase letters)) = (letter (i) of (string))>
change [i2 v] by (1)
end
set [return v] to (join (return)(letter (i2) of (lowercase letters)))
end
- Discussion Forums
- » Help with Scripts
-
» String to Lowercase