% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/UTF8pgm.R
\name{cchar}
\alias{cchar}
\title{Starting and Ending Columns of Each Character in a Text File}
\usage{
cchar(x, from = NULL, to = NULL, last = TRUE)
}
\arguments{
\item{x}{A string vector}
}
\value{
When \code{from} is not given, a list of matrices
\code{FT[[i]]} where \code{FTT[[i]][j,1]} and \code{FTT[[i]][j,2]},
resp, are the starting and ending columns of the \code{j}-th character
of the \code{i}-th string.
When the input is a string, \code{FT[[1]]} will be returned.
\cr
When \code{from} is given, a list of matrices
\code{FTc[[i]]} corresponding to each of the strings where
\code{FTc[[i]][j,1], FTc[[i]][j,2]} are, resp,
the starting and ending characters corresponding to
\code{from[j]} and \code{to[j]} of the i-th string.
}
\description{
Starting and Ending Columns of Each Character in a Text File
}
\details{
This function can be used to get the substring of a string
by specifying the starting and the ending columns. \cr
It is assumed that the double or triple byte characters takes two columns
of a text file.  (Zenkaku Character)

If \code{x} contains a string consisting of single and multibyte characters,
\preformatted{
 ft <- cchar(x)
 substr( x, which(ft[,1] == start), To=which(ft[,2] == stop) )
}
will return the characters between columns \code{start} and \code{stop}.
}
\examples{
# A string consisting of single and multi byte characters
# The 3rd, 6th and 7th characters are uppercase Zenkaku Romans.
{if( regexpr("utf8",Sys.getlocale (category = "LC_CTYPE")) > 0 )
 nza <- c(97, 98, 239, 188, 163, 100, 101, 239, 188, 166, 239, 188, 167, 104)
else
 nza <- c(97,98,130,98,100,101,130,101,130,102,104)}
za <- rawToChar(as.raw(nza))
# za <- num2char(nza)

# location of the multi byte characters
nchar(za)
is.DBCS(za)
printm( nchar(za), nchar2(za), nchar(za)+sum(is.DBCS(za)) )
printm(1:nchar(za), unlist(strsplit(za,"")),nbyte(za),cchar(za))

# When input is a string vector
cchar(c(za,za))

# convert column position to character position
# from and to as column position
from <- c(1,2,3,5,6,7,9,11)
to <- c(1,2,4,5,6,8,10,11)
# character position corresponding to (from,to) to be used in substr(ing)
FTc <- cchar(za,from,to)[[1]]
# substrings
ssg <- substring(za,FTc[,1],FTc[,2])
# substrings using substr2 which can hadle column (from,to)
ss2 <- substr2(za,from,to)
za1 <- strsplit(za,"")[[1]]   # to print each character
printm(za1, from, to, FTc, ssg,ss2)

# use of last option
cchar( za, 1:11, 1:11 )
cchar( za, 1:11, 1:11, last=0 )

cchar( za, 3,4 )
cchar( za, 3,5 )
cchar( za, 3,7 )
cchar( za, 3,7, last=0 )

# When input is a string vector
cchar( c(za,za), 1:11, 1:11, last=0 )


}
