Skip to content

Instantly share code, notes, and snippets.

@IshamMohamed
Last active December 29, 2015 02:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IshamMohamed/7603039 to your computer and use it in GitHub Desktop.
Save IshamMohamed/7603039 to your computer and use it in GitHub Desktop.
using System.Net;
//this method can be called in a button tap event
private void calculate()
{
string calculationText = txtInput.Text;
try
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += HttpCompleted;
string uri = String.Format("http://gcdc2013-easyapisproject.appspot.com/eval?q={0}", WebUtility.UrlEncode(calculationText));
wc.DownloadStringAsync(new Uri(uri));
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
private void HttpCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
string result = e.Result;
result = result.Substring(1);
result = result.Remove(result.Length - 1);
string[] results = result.Split(new string[] { "}{" }, StringSplitOptions.None);
result = results[1];
if (result != "URL Encode/Decode Error, Escape specl chars")
MessageBox.Show(result);
else
MessageBox.Show("Couldn't perform equation");
}
catch (Exception err)
{
MessageBox.Show("No Internet connectivity, please connect to internet to perform");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment