change font with endswith() method

edited May 2017 in Questions about Code

Hi guys, i am making a programm in which you can change the font, fontsize, color etc. dynamically based on the punctuation you give at the end of the sentence. for example:

if (myText.endsWith("!") == true) {
  fill(255,0,0);
font = createFont("HelveticaNeueLTStd-Bd.ttf",100);
} 
else if (myText.endsWith("!!") == true) {
  fill(0,255,0);
font = createFont("HelveticaNeueLTStd-Bd.ttf",120);
} 
else if (myText.endsWith("!!!") == true) {
  fill(0,0,255);
font = createFont("HelveticaNeueLTStd-Bd.ttf",150);
}  

but the programm doesn`t make a difference between "!" and "!!" or "!!!". can somebody help me out and say why?

Answers

  • edited May 2017 Answer ✓

    Check "!!!" before the others:

    if      (myText.endsWith("!!!")) font = createFont("HelveticaNeueLTStd-Bd.ttf", 150);
    else if (myText.endsWith("!!"))  font = createFont("HelveticaNeueLTStd-Bd.ttf", 120);
    else if (myText.endsWith("!"))   font = createFont("HelveticaNeueLTStd-Bd.ttf", 100);
    
  • yeah thank you for the tip! youre great! sorry for the late respond :D

Sign In or Register to comment.