TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

Swedish Chef Translation Contest

I wrote this to make Eric Gunnerson laugh. What do you think, should I enter this into the contest?  :-)

using System;

using System.Net;

using System.Text;

using System.IO;

 

class Chef

{

    public static string Convert(string text)

    {

        WebRequest request = HttpWebRequest.Create("http://rinkworks.com/dialect/dialectt.cgi");

        request.Method = "POST";

        string postData="dialect=bork&text=" + text;

        ASCIIEncoding encoding = new ASCIIEncoding();

        byte[] bytes = encoding.GetBytes(postData);

        request.ContentType="application/x-www-form-urlencoded";

        request.ContentLength = postData.Length;

        Stream requestStream = request.GetRequestStream();

        requestStream.Write(bytes, 0, bytes.Length);

        requestStream.Close();

 

        HttpWebResponse objResponse = (HttpWebResponse) request.GetResponse();

        string result = String.Empty;

        using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))

        {

            result = sr.ReadToEnd();

            sr.Close();

        }

       

        int start = result.IndexOf("</h2></center><p>") + "</h2></center><p>".Length;

        int end = result.IndexOf("<p><br><hr>", start);

 

        return result.Substring(start, end - start);

    }

}

 

 

class App

{

      [STAThread]

      static void Main(string[] args)

      {

        string value = Chef.Convert("This code is not a major hack. It is robust, scalable, maintainable, etc.");

        Console.WriteLine(value);

      }

}


Digg!

posted on Wednesday, December 01, 2004 11:13 AM

Feedback

No comments posted yet.