We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When the string -english- contains #,$,%,&, or q, and you press backspace, one character is to be deleted from -english-, and 2 from -tenglish-. All other times when you press backspace, one character is removed from both. However, this code deletes a massive chunk of text on the first press, then almost (but not quite) does what it's supposed to. I've been pouring over it for a few minutes, anyone willing to give me a quick debug?
String english = "";
String tenglish = "";
PFont f;
void setup() {
size(500, 650);
f = loadFont("ArialMT-30.vlw");
textFont(f, 12);
}
void draw() {
background(255);
fill(0);
text(english, 0, height-30);
text(tenglish, 0, height-100);
}
void keyReleased() {
if (key!=BACKSPACE&&key!=CODED&&key!=DELETE&&key!=ENTER) {
english+=key;
tenglish+=key;
}
transliterate();
}
void keyPressed() {
if (key ==BACKSPACE&&english.length()>0) {
if (english.charAt(english.length()-1)== '#' && english.charAt(english.length()-1)== ' && english.charAt(english.length()-1)== '%' && english.charAt(english.length()-1)== '&' && english.charAt(english.length()-1)== 'q') {
tenglish = tenglish.substring(0, english.length()-2);
}
else {
tenglish = tenglish.substring(0, english.length()-1);
}
english = english.substring(0, english.length()-1);
}
}
void transliterate() {
english=english.toLowerCase();
english=join(split(english, "ch"), "#");
english=join(split(english, "sh"), "$");
english=join(split(english, "th"), "%");
english=join(split(english, "ng"), "&");
english=join(split(english, "qu"), "q");
}
Answers
Online text box example:
http://studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest
This isn't what I need, sorry. Unless you can show me how to apply it?
Well, I found one problem:
This line (28-30): if (english.charAt(english.length()-1)== '#' && english.charAt(english.length()-1)== ' && english.charAt(english.length()-1)== '%' && english.charAt(english.length()-1)== '&' && english.charAt(english.length()-1)== 'q') { tenglish = tenglish.substring(0, english.length()-2); }
should have ||'s instead of &&'s.
The other problem is that I reformat the wrong strings on lines 29 and 32. Problem solved!
I think
This line (28-30):
can be written as
example:
(one $ sign in your code is missing the forum killed it ?)
or even:
Wound up doing this: