ralfkausk
Goto Top

Powershell Funkalphabet

Hallo zusammen

Ich bräuchte mal ein paar Tips
Ich möchte mit der Powershell eine Funkalphabet "Übersetzung" bauen.

Ganz konkret:
Ich gebe ein Wort ein und erhalte dazu die passende Ausgabe als Funkalphabet
z.B.:
Eingabe: Hallo
Ausgabe:
h Heinrich
a Anton
l Ludwig
l Ludwig
o Otto

Ich habe es schon probier, komme aber leider auf keinen grünen Zweig.
Kann mir jemand auf die Sprünge helfen?

cls
Write-Host ""  
$WORD = Read-Host "Please enter the word to be translated ..." `  
Write-Host ""  
Write-Host "Your word is: $WORD"  
Write-Host ""  

$WORD = $WORD -replace "(\w{1})", "`$1`n"|ForEach-Object `  
    {$_ -replace "[Aa]", "$a"}  
    {$_ -replace "[Bb]", "$b"}  
    {$_ -replace "[Cc]", "$c"}  
    {$_ -replace "[Dd]", "$d"}  
    {$_ -replace "[Ff]", "$f"}  
    {$_ -replace "[Gg]", "$g"}  
    {$_ -replace "[Cc]", "$c"}  
    {$_ -replace "[Dd]", "$d"}  
    {$_ -replace "[Ee]", "$e"}  
    {$_ -replace "[Ff]", "$f"}  
    {$_ -replace "[Gg]", "$g"}  
    {$_ -replace "[Hh]", "$h"}  
    {$_ -replace "[Ii]", "$i"}  
    {$_ -replace "[Jj]", "$j"}  
    {$_ -replace "[Kk]", "$k"}  
    {$_ -replace "[Ll]", "$l"}  
    {$_ -replace "[Mm]", "$m"}  
    {$_ -replace "[Nn]", "$n"}  
    {$_ -replace "[Oo]", "$o"}  
    {$_ -replace "[Pp]", "$p"}  
    {$_ -replace "[Qq]", "$q"}  
    {$_ -replace "[Rr]", "$r"}  
    {$_ -replace "[Ss]", "$s"}  
    {$_ -replace "[Tt]", "$t"}  
    {$_ -replace "[Uu]", "$u"}  
    {$_ -replace "[Vv]", "$v"}  
    {$_ -replace "[Ww]", "$w"}  
    {$_ -replace "[Xx]", "$x"}  
    {$_ -replace "[Yy]", "$y"}  
    {$_ -replace "[Zz]", "$z"}  

Write-Host $WORD

Ich hatte gehofft das funktioniert nach dem gleichen Prinziep wie:
$1 = "hallo"  
$1 -replace "l", "g" -replace "h", "p"  

Ausgabe: paggo

Content-Key: 245843

Url: https://administrator.de/contentid/245843

Printed on: April 26, 2024 at 19:04 o'clock

Member: colinardo
Solution colinardo Aug 07, 2014, updated at Aug 10, 2014 at 15:16:27 (UTC)
Goto Top
Moin Ralf,
$tableDE = @{"A"="Anton";"B"="Berta";"C"="Cäsar";"D"="Dora";"E"="Emil";"F"="Friedrich";"G"="Gustav";"H"="Heinrich";"I"="Ida";"J"="Julius";"K"="Konrad";"L"="Ludwig";"M"="Martha";"N"="Nordpol";"O"="Otto";"P"="Paula";"Q"="Quelle";"R"="Richard";"S"="Siegfried";"T"="Theodor";"U"="Ulrich";"V"="Viktor";"W"="Wilhelm";"X"="Xaver";"Y"="Ypsilon";"Z"="Zacharias";"Ä"="Ärger";"Ö"="Ökonom";"Ü"="Übermut";"@"="Schule"}  
$tableINT = @{"A"="Alpha";"B"="Bravo";"C"="Charly";"D"="Delta";"E"="Echo";"F"="Foxtrott";"G"="Golf";"H"="Hotel";"I"="India";"J"="Juliet";"K"="Kilo";"L"="Lima";"M"="Mike";"N"="November";"O"="Oscar";"P"="Papa";"Q"="Quebec";"R"="Romeo";"S"="Sierra";"T"="Tango";"U"="Uniform";"V"="Victor";"W"="Whiskey";"X"="X-Ray";"Y"="Yankee";"Z"="Zulu"}  
$language = Read-host "Welche Sprache [1] Deutsch | [2] Englisch ?"  
switch($language){
    1{
        $input = read-host "Wort eingeben das übersetzt werden soll"   
        $input = $input -Replace "sch","@"  
        $input.ToCharArray() | %{write-host $tableDE["$_"] -ForegroundColor Green}  
    }
    2{
        $input = read-host "Please enter word to be translated"  
        $input.ToCharArray() | %{write-host $tableINT["$_"] -ForegroundColor Green}  
    }
    default{write-host "Keine gültige Sprache gewählt!" -ForegroundColor Red}  
}
Grüße Uwe
Member: aqui
aqui Aug 07, 2014 updated at 11:26:43 (UTC)
Goto Top
Das ist aber nur das deutsche Funkalphabet und nicht das internationale !!
Hier hat man beide:
http://felixbernhard.kuenneke.info/down/Funk.pdf
Müsste Kollege colinardo also noch einen Schalter "Deutsch oder International ?" mit einpflanzen face-wink

Beim deutschen oben fehlen außerdem noch Ärger, Ökonom, Übermut und Schule.
Member: ralfkausk
ralfkausk Aug 07, 2014 at 11:22:15 (UTC)
Goto Top
Wow, cool
Das funktioniert perfekt

Vielen Dank
Member: aqui
aqui Aug 07, 2014 at 11:24:43 (UTC)
Goto Top
Bitte dann auch
How can I mark a post as solved?
nicht vergessen.
Member: colinardo
colinardo Aug 07, 2014 updated at 11:50:42 (UTC)
Goto Top
Zitat von @aqui:
Müsste Kollege colinardo also noch einen Schalter "Deutsch oder International ?" mit einpflanzen face-wink

Beim deutschen oben fehlen außerdem noch Ärger, Ökonom, Übermut und Schule.
jetzt ist @aqui hoffentlich auch zufrieden face-smile... habe ich das Script oben wie gewünscht ergänzt.
Member: AnkhMorpork
Solution AnkhMorpork Aug 10, 2014, updated at Aug 12, 2014 at 06:59:14 (UTC)
Goto Top
Zitat von @colinardo:

Moin Ralf,
> $tableDE =
> @{"A"="Anton";"B"="Berta";"C"="Cäsar";"D"="Dora";"E"="Emil";"F"="Friedrich";"G"="Gustav";"H"="Heinrich";"I"="Ida";"J"="Julius";"K"="Konrad";"L"="Ludwig";"M"="Martha";"N"="Nordpol";"O"="Otto";"P"="Paula";"Q"="Quelle";"R"="Richard";"S"="Siegfried";"T"="Theodor";"U"="Ulrich";"V"="Viktor";"W"="Wilhelm";"X"="Xaver";"Y"="Ypsilon";"Z"="Zürich";"Ä"="Ärger";"Ö"="Ökonom";"Ü"="Übermut";"@"="Schule"}  
> $tableINT =
> @{"A"="Alpha";"B"="Bravo";"C"="Charly";"D"="Delta";"E"="Echo";"F"="Foxtrott";"G"="Golf";"H"="Hotel";"I"="India";"J"="Juliet";"K"="Kilo";"L"="Lima";"M"="Mike";"N"="November";"O"="Oscar";"P"="Papa";"Q"="Quebec";"R"="Romeo";"S"="Sierra";"T"="Tango";"U"="Uniform";"V"="Victor";"W"="Whiskey";"X"="X-Ray";"Y"="Yankee";"Z"="Zulu"}  
> $language = Read-host "Welche Sprache [1] Deutsch | [2] Englisch ?"  
> switch($language){
>     1{
>         $input = read-host "Wort eingeben das übersetzt werden soll"   
>         $input = $input -Replace "sch","@"  
>         $input.ToCharArray() | %{write-host $tableDE["$_"] -ForegroundColor Green}  
>     }
>     2{
>         $input = read-host "Please enter word to be translated"  
>         $input.ToCharArray() | %{write-host $tableINT["$_"] -ForegroundColor Green}  
>     }
>     default{write-host "Keine gültige Sprache gewählt!" -ForegroundColor Red}  
> }
> 
Grüße Uwe

Z = Zacharias??? Sind doch keine Swisser hier ... face-smile

Gruß
ANKH
Member: colinardo
colinardo Aug 10, 2014 updated at 15:22:50 (UTC)
Goto Top
Zitat von @AnkhMorpork:
Z = Zacharias???
Stimmt, da hat der alte Alm-Öhi in mir einen kleines Osterei versteckt face-smile
Sind doch keine Swisser hier ... face-smile
mehr als du denkst ....hatte hier bestimmt schon mit mehr als 10 Leuten aus den schönen Bergen Kontakt - und die sind meist schneller im Netz unterwegs als wir !! Ich sag nur 1Gbit/s face-wink

Grüße Uwe
Member: AnkhMorpork
AnkhMorpork Aug 10, 2014 at 15:25:12 (UTC)
Goto Top
Zitat von @colinardo:

> Zitat von @AnkhMorpork:
> Z = Zacharias???
Stimmt, da hat der alte Alm-Öhi in mir einen kleines Osterei versteckt face-smile
Dem Ei sei Dank!

> Sind doch keine Swisser hier ... face-smile
mehr als du denkst ....hatte hier bestimmt schon mit mehr als 10 Leuten aus den schönen Bergen Kontakt.

Wir sind unterwandert??? ... Oh man... viva suisse!
Member: ralfkausk
ralfkausk Aug 12, 2014 at 07:06:48 (UTC)
Goto Top
@colinardo: Die Sache mit dem switch gefällt mir auch sehr gut.
Ich hatte mit zwischenzeitlich auch schon was drumherum gebaut, allerdings etwas aufwändiger.
Außerdem habe ich auch noch Zahlen mit eingebaut ... man weiß ja nie wofür man's mal braucht

<#
!/bin/ksh ;-)
Name:				FUNKALPHABET.ps1
Author:				Ralf K aus K
Created:				2014-08-07
Last update:			2014-08-07

What's it all about:	Translate word(s) into Funkalphabet ;)  

#>

###########################################
### Adds a pause function to Powershell ###
function Pause ($pmessage="Press any key to continue...")  
{
Write-Host -NoNewLine $pmessage
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")  
Write-Host ""  
}
### Adds a pause function to Powershell ###
###########################################

##########################################################
### Change to directory to where the script is started ###
$parentPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
cd $parentPath
### Change to directory to where the script is started ###
##########################################################

### Create a Date / Time variable
$CDATETIME = get-date -format yyyy-MM-dd-HH-mm

### Create a Filename variable with current Date / Time
$FILENAME = "xxx"+"_"+$CDATETIME  

$TABLEDE = @{
"A"="Anton";"B"="Berta";"C"="Cäsar";"D"="Dora";"E"="Emil";`  
"F"="Friedrich";"G"="Gustav";"H"="Heinrich";"I"="Ida";"J"="Julius";"K"="Konrad";`  
"L"="Ludwig";"M"="Martha";"N"="Nordpol";"O"="Otto";"P"="Paula";"Q"="Quelle";"R"="Richard";`  
"S"="Siegfried";"T"="Theodor";"U"="Ulrich";"V"="Viktor";"W"="Wilhelm";"X"="Xaver";`  
"Y"="Ypsilon";"Z"="Zürich";"ß"="Esszet";"ä"="Ärger";"ö"="Ökonom";"ü"="Übermut";`  
"0"="Null";"1"="Eins";"2"="Zwei";"3"="Drei";"4"="Vier";"5"="Fünf";"6"="Sechs";"7"="Sieben";"8"="Acht";"9"="Neun"}  

$TABLEEN = @{
"A"="Alfa";"B"="Bravo";"C"="Charlie";"D"="Delta";"E"="Echo";"F"="Foxtrot";`  
"G"="Golf";"H"="Hotel";"I"="India";"J"="Juliett";"K"="Kilo";"L"="Lima";"M"="Mike";`  
"N"="November";"O"="Oscar";"P"="Papa";"Q"="Quebec";"R"="Romeo";"S"="Sierra";"T"="Tango";`  
"U"="Uniform";"V"="Victor";"W"="Whiskey";"X"="X-Ray";"Y"="Yankee";"Z"="Zulu";`  
"0"="Zero";"1"="One";"2"="Two";"3"="Three";"4"="Four";"5"="Five";"6"="Six";"7"="Seven";"8"="Eight";"9"="Nine"}  

function TRANSLATEDE {
cls
Write-Host ""  
$INPUTDE = read-host "EINGABE DEUTSCH"  
Write-Host ""  
Write-Host "Deine Eingabe: $INPUTDE"  
Write-Host ""  
Write-Host "Übersetzung:"  
Write-Host ""  
$INPUTDE.ToCharArray() | %{write-host $TABLEDE["$_"]}}  

function TRANSLATEEN {
cls
Write-Host ""  
$INPUTEN = read-host "INPUT INTERNATIONAL"  
Write-Host ""  
Write-Host "Your Input: $INPUTEN"  
Write-Host ""  
Write-Host "Translation:"  
Write-Host ""  
$INPUTEN.ToCharArray() | %{write-host $TABLEEN["$_"]}}  

$COUNTER = 0
do {

# Here we go ...
clear
$1 = New-Object System.Management.Automation.Host.ChoiceDescription "&1 GERMAN", `  
    "Get all AD groups from a specific user"  
$2 = New-Object System.Management.Automation.Host.ChoiceDescription "&2 INTERNATIONAL", `  
    "Get all members of a specific AD group"  
$9 = New-Object System.Management.Automation.Host.ChoiceDescription "&9 Do nothing", `  
    "Do nothing"  

$options = [System.Management.Automation.Host.ChoiceDescription[]]($1, $2, $9)
$result = $host.ui.PromptForChoice($title, $message, $options, 2) # 0 indicates the pre-defined choice, in that case yes. 1 would be no, and so on ...

switch ($result)
    {

########################### Translate to German spelling

        0 {
        TRANSLATEDE
        Write-Host ""  
        #pause
        }
########################### Translate to German spelling
########################### Translate to Internation spelling

        1 {
        TRANSLATEEN
        Write-Host ""  
        #pause
        }
########################### Translate to Internation spelling
########################### Do Nothing

        8 {
        echo "Do nothing"  
        }
########################### Do Nothing
}
$RESPONSE = Read-Host "Start again (Yes|No)?"  
$COUNTER++
}
while ($RESPONSE -eq "Y")  

Ich möchte mich bei allen für die Unterstützung bedanken.

Gruß Ralf