Find and accent a vowel

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Find and accent a vowel

#1 Post by batchcc » 09 Apr 2017 05:52

I have looked around and found multiple ways to replace a letter for example: http://stackoverflow.com/questions/13469939/replacing-characters-in-string; however, I need to replace the third vowel (aeiou not y) in a word with its accented form (áéíóú). For example

Example > examplé
Fashion > fashión

Each word will have at least three vowels.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find and accent a vowel

#2 Post by aGerman » 09 Apr 2017 08:28

It always depends on you codepage settings if non-ASCII characters work. You may try this

Code: Select all

@echo off &setlocal EnableDelayedExpansion

for /f "tokens=2 delims=:" %%i in ('chcp') do set /a oemcp=%%~ni
for /f "tokens=3" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP"') do set /a acp=%%i
>nul chcp %acp%
for %%i in ("a=á" "e=é" "i=í" "o=ó" "u=ú") do set %%i
>nul chcp %oemcp%


for %%i in (
  example
  fashion
) do (
  set "word=%%~i"
  set "word="!word:a=" "a" "!""
  set "word=!word:e=" "e" "!"
  set "word=!word:i=" "i" "!"
  set "word=!word:o=" "o" "!"
  set "word=!word:u=" "u" "!"
  set "n=0"
  set "newword="
  for %%j in (!word!) do (
    set /a "n+=1"
    if !n!==6 (
      set "newword=!newword!!%%~j!"
    ) else (
      set "newword=!newword!%%~j"
    )
  )
  echo !newword!
)

pause

Steffen

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: Find and accent a vowel

#3 Post by batchcc » 09 Apr 2017 14:46

Thanks aGerman, I cant wait to try it!

Post Reply