ourMELONS/R/rivinSisaltamienMjonojenLkm.R

26 lines
844 B
R
Raw Normal View History

2020-06-24 12:11:54 +02:00
#' @title Number of M queues
#' @param line line number
#' @return count
#' @description Returns the number of queues contained in the line. There must be a space between the queues.
2020-06-24 12:11:54 +02:00
rivinSisaltamienMjonojenLkm <- function(line) {
# Palauttaa line:n sis<69>lt<6C>mien mjonojen lukum<75><6D>r<EFBFBD>n.
# Mjonojen v<>liss?t<>ytyy olla v<>lily<6C>nti.
count <- 0
pit <- nchar(line)
tila <- 0 # 0, jos odotetaan v<>lily<6C>ntej? 1 jos odotetaan muita merkkej?
for (i in seq_len(pit)) {
merkki <- substring(line, i, i)
if (isspace(merkki) & tila == 0) {
# Ei tehd?mit<69><74>n.
} else if (isspace(merkki) & tila == 1) {
tila <- 0
} else if (!isspace(merkki) & tila == 0) {
tila <- 1
count <- count + 1
} else if (!isspace(merkki) & tila == 1) {
# %Ei tehd?mit<69><74>n
}
}
return(count)
}