
#----------------------------------#
  ## SAMPLE STRING
  
  strng <- "Sigur RÃÃ³s - ab,cd.txt"

#----------------------------------#
  splat <- strsplit(strng, "")[[1]]
  names(splat) <- 1:length(splat)
  splat
#----------------------------------#


  ASCII_regex <- "[^\\x00-\\x7F]"
  WORDS_regex <- "[^\\w\\*]"
  Simple_regex <- "[^0-9a-zA-Z -.]"

  str_locate_all(strng, Simple_regex) [[1]]
  str_locate_all(strng, ASCII_regex) [[1]]
  str_locate_all(strng, WORDS_regex) [[1]]



#=================================================#
#-------------------------------------------------#
#              REPLACING CHARACTERS               #
#-------------------------------------------------#
#=================================================#


          Simple_regex <- "[^0-9a-zA-Z -.]"
          stringVec <- c("hello~world!", "Si~g'u`r RÃÃ³s - ab,cd.txt", "NEXT: on!@#$%^&*().txt")
          cleanChar <- "_"


        #-------------------------------------------------#
        #        using library(stringr)                   #
        #-------------------------------------------------#
          library(stringr)

          badChars <- str_locate_all(stringVec, pattern=Simple_regex)  

          for (ind in 1:length(badChars))
            for (r in 1:nrow(badChars[[ind]]))
                substr(stringVec[[ind]], badChars[[ind]][r, "start"], badChars[[ind]][r, "end"]) <- cleanChar

          stringVec

        #-------------------------------------------------#
        #        using regex / gsub                       #
        #-------------------------------------------------#

          stringVec <- gsub(Simple_regex, cleanChar, stringVec)  

          stringVec

        #-------------------------------------------------#
