Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to manipulate elements in Rcpp::String

$
0
0

Is there possible to manipulate individual characters with Rcpp::string object? I need to do some string substitutions while keeping encodings, so I think Rcpp::string might help.

What I want to achieve is something like:

// [[Rcpp::export]]
Rcpp::string demo1(const Rcpp::String txt) {
  std::string s = txt.get_cstring();  // this would lose character encoding.

  int nlen = s.size();    
  char out[nlen];

  for (int i=0; i<nlen; i++) {
    // if match condition then
    out[i] = s[i];
  }
  return out;
}

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>