sent = input('give me a sentence, please: ','s') spaces = sent==' '; s1 = sent; words = sum(spaces) + 1 starts = [1 (find(spaces) + 1)] diff = 'a'-'A' sent(starts) = sent(starts) - diff; char(sent) nospaces = ~spaces sent(nospaces) = s1(nospaces) - diff; char(sent)