Skip to content

Instantly share code, notes, and snippets.

@adamori
Created December 25, 2022 21:44
Show Gist options
  • Save adamori/ef38b3f8dc62b02d53fc1d25753c66ea to your computer and use it in GitHub Desktop.
Save adamori/ef38b3f8dc62b02d53fc1d25753c66ea to your computer and use it in GitHub Desktop.
This code is a batch script that converts Estonian characters in a string to HTML code and counts the number of Estonian characters. It takes a single argument as input, which should be the string to be processed, and outputs the converted string and the character counts.
@echo off
setlocal enabledelayedexpansion
:: Set character encoding to UTF-8 to support Estonian characters
@chcp 65001
:: Check if argument was provided
if "%~1" == "" ( echo No arguments... & exit /b )
:: Set string and initialize variables
set str=%1
set tempstr=%str%
set count=0
:: Get length of string
:loop
if defined tempstr (
set tempstr=%tempstr:~1%
set /a count+=1
goto loop
)
:: Initialize variables for character counts
set i=0
set found=0
:: Loop through string and count Estonian characters
:loop2
set "char=!str:~%i%,1!"
if "ä" EQU "!char!" (
set /a ä_lower+=1
set found=1
)
if "ö" EQU "!char!" (
set /a ö_lower+=1
set found=1
)
if "ü" EQU "!char!" (
set /a ü_lower+=1
set found=1
)
if "õ" EQU "!char!" (
set /a õ_lower+=1
set found=1
)
if "š" EQU "!char!" (
set /a š_lower+=1
set found=1
)
if "ž" EQU "!char!" (
set /a ž_lower+=1
set found=1
)
if "Ä" EQU "!char!" (
set /a ä_upper+=1
set found=1
)
if "Ö" EQU "!char!" (
set /a ö_upper+=1
set found=1
)
if "Ü" EQU "!char!" (
set /a ü_upper+=1
set found=1
)
if "Õ" EQU "!char!" (
set /a õ_upper+=1
set found=1
)
if "Š" EQU "!char!" (
set /a š_upper+=1
set found=1
)
if "Ž" EQU "!char!" (
set /a ž_upper+=1
set found=1
)
:: Move to next character in string
set /A i+=1
if not %i% GTR %count% (
goto loop2
)
:: FOR STATEMENT END
:: Replace Estonian characters with HTML code
set str=%str:ä=ä%
set str=%str:ö=ö%
set str=%str:ü=ü%
set str=%str:õ=õ%
set str=%str:š=š%
set str=%str:ž=ž%
set str=%str:Ä=Ä%
set str=%str:Ö=Ö%
set str=%str:Ü=Ü%
set str=%str:Õ=Õ%
set str=%str:Š=Š%
set str=%str:Ž=Ž%
:: Print converted string
echo.
echo.%str%
echo.
:: Print character counts
if %found% EQU 1 (
echo Vahetatud:
echo.
if defined ä_lower echo ä: %ä_lower%
if defined ö_lower echo ö: %ö_lower%
if defined ü_lower echo ü: %ü_lower%
if defined õ_lower echo õ: %õ_lower%
if defined š_lower echo š: %š_lower%
if defined ž_lower echo ž: %ž_lower%
if defined ä_upper echo Ä: %ä_upper%
if defined ö_upper echo Ö: %ö_upper%
if defined ü_upper echo ü: %ü_upper%
if defined õ_upper echo Õ: %õ_upper%
if defined š_upper echo Š: %š_upper%
if defined ž_upper echo Ž: %ž_upper%
set /A kokku=ä_lower+ö_lower+ü_lower+õ_lower+š_lower+ž_lower+ä_upper+ö_upper+ü_upper+õ_upper+š_upper+ž_upper
set kokku
echo.
) else (
echo Ei leidnud ühtegi täpitähte
echo.
)
@adamori
Copy link
Author

adamori commented Dec 25, 2022

convert.bat "Ao äia õe uue oaõieaia õueaua ööau"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment