% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/char2num.R
\name{char2num}
\alias{char2num}
\alias{num2char}
\title{Convert a Character Vector to a List of Numeric Vectors
 or vice versa via raw expression.}
\usage{
char2num(char)

num2char(num)
}
\arguments{
\item{char}{a vector of strings}

\item{num}{a list of numeric vectors or a numeric vector
which can be converted to string via raw conversion.}
}
\value{
char2num \cr
If char is a string ( a vector of length 1 ), num is a vector. \cr
If char is a vector of strings, num is a list of length(char) \cr
\cr
num2char \cr
If num is a vector, char is a string. \cr
If num is a list, char is a vector of strings of length(num) \cr
}
\description{
Convert a Character Vector to a List of Numeric Vectors
 or vice versa via raw expression.
}
\details{
Since these functions can handle multi byte characters, \cr
they can be used to store the strings with multi byte characters
as a list of numeric vectors. \cr

The core part of these functions are: \cr
char to num
\preformatted{
 num <- as.numeric( charToRaw(char) )
}
num to char
\preformatted{
char <- rawToChar( as.raw( num ) )
}

The numbers and Raw expression are related as
\preformatted{
 num <- char2num( char )
 ( hex <- as.hexmode( num ) )
 print( as.raw(num) )
}
}
\examples{
# char is a string
( char <- "This is an example." )
( num <- char2num( char ) )
( is.numeric(num) )
( char2 <- num2char( num ) )

# char is a string vector
( char2 <- c("This is an example.", "2nd line") )
( num2 <- char2num( char2 ) )
( sapply( num2, is.numeric ) )
( char22 <- num2char( num2 ) )

# storing multi byte characters in a package: \cr
# See the description of 'generate_zenkaku_sets'.
{if( regexpr("utf8",Sys.getlocale (category = "LC_CTYPE")) > 0 )
 nn <- c(87, 101,  32, 104,  97, 118, 101,  32, 228, 184, 141, 232, 184
         , 176, 231, 159, 169,  32, 121, 101, 116,  33)
else
 nn <- c(87, 101,  32, 104,  97, 118, 101,  32, 149, 115, 230, 250, 139
         , 233, 32, 121, 101, 116,  33)}
( zz <- num2char(nn) )
( zzh <- as.hexmode(nn) )
charToRaw(zz)


}
