Sunday, October 22, 2006

Translate Swedish words to English

This script was inspired by a colleague of mine who wanted to create a translation-thingy.
Anyway, the concept is easy. The script POST:s the query to Skoldatanätet (who operates a english/swedish translationservice through a regular html-page) and uses Regular Expression to match the result (the second entry which is contained in a HTML <B>-tag.

I'm sure there are better ways to read input and output the result, but since I'm a C#-programmer I used the .NET Framework functions because I'm lazy.. ;)

[Console]::Write("Swedish: ")
[Console]::WriteLine("English: " + [RegEx]::Match([System.Text.Encoding]::ASCII.GetString((New-Object net.webclient).UploadData("", "POST", [System.Text.Encoding]::ASCII.GetBytes("sprak=källspråk&uppslagsord=" + [Console]::ReadLine().Trim()))),"<B\b[^>]*>(.*?)</B>").NextMatch().Groups[1].Value)


Post a Comment

Subscribe to Post Comments [Atom]

<< Home