mdb_ftl
mdb_ftl

Reputation: 443

Generate full width character string in R

In R, how can I make the following:

convert this string: "my test string"

to something like this ( a full width character string): "my  test  string"

is there a way to do this through hexidecimal character encodings?

Thanks for your help, I'm really not sure how to even start. Perhaps something with {stringr}

I'm trying to get an output similar to what I would expect from this online conversion tool:

http://www.linkstrasse.de/en/%EF%BD%86%EF%BD%95%EF%BD%8C%EF%BD%8C%EF%BD%97%EF%BD%89%EF%BD%84%EF%BD%94%EF%BD%88%EF%BC%8D%EF%BD%83%EF%BD%8F%EF%BD%8E%EF%BD%96%EF%BD%85%EF%BD%92%EF%BD%94%EF%BD%85%EF%BD%92

Upvotes: 0

Views: 69

Answers (1)

AndrewGB
AndrewGB

Reputation: 16856

Here is a possible solution using a function from the archived Nippon package. This is the han2zen function, which can be found here.

x <- "my test string"

han2zen <- function(s){
  stopifnot(is.character(s))
  zenEisu <- paste0(intToUtf8(65295 + 1:10), intToUtf8(65312 + 1:26),
                    intToUtf8(65344 + 1:26))
  zenKigo <- c(65281, 65283, 65284, 65285, 65286, 65290, 65291,
               65292, 12540, 65294, 65295, 65306, 65307, 65308,
               65309, 65310, 65311, 65312, 65342, 65343, 65372,
               65374)
  s <- chartr("0-9A-Za-z", zenEisu, s)
  s <- chartr('!#$%&*+,-./:;<=>?@^_|~', intToUtf8(zenKigo), s)
  s <- gsub(" ", intToUtf8(12288), s)
  return(s)
}


han2zen(x)

# [1] "my test string"

Upvotes: 1

Related Questions