Here is a little code that counts letters in English words:
words <- c("miscognizable", "harvestry", "geopolitist", "jessed", "pardonee", "whitfield", "ghazal", "morphophonemically", "calonectria","conceptiveness")
for (i in 1:length(words)) {
char_count <- nchar(words[i])
cat(words[i], ":", char_count, "characters\n", sep = " ")
}
miscognizable : 13 characters
harvestry : 9 characters
geopolitist : 11 characters
jessed : 6 characters
pardonee : 8 characters
whitfield : 9 characters
ghazal : 6 characters
morphophonemically : 18 characters
calonectria : 11 characters
conceptiveness : 14 characters
To my surprise the code works with Hebrew words, which are written right to left, except that the cat print statement is printing word, colon, and count right to left. How I can I correct this?
words <- c("מלך", "ממשלה", "פרח", "מחשב", "תפוח", "כתב", "בית", "שקט", "צהריים", "שמיים")
for (i in 1:length(words)) {
char_count <- nchar(words[i])
cat(words[i], ":", char_count, "characters\n", sep = " ")
}
3 characters
ממשלה : 5 characters
פרח : 3 characters
מחשב : 4 characters
תפוח : 4 characters
כתב : 3 characters
בית : 3 characters
שקט : 3 characters
צהריים : 6 characters
שמיים : 5 characters