1

I have string which is like this:

string line = "77.139305\t28.795975"

and i seperate the two integers like this:

string lat = line.Substring(0, 9);
string lng = line.Substring(10, 9);

whic exactly seperates the 2 numbers like this: "77.139305" and "28.795975" for lat and lng.

  int latitude,longitude;
   bool result = Int32.TryParse(lat, out latitude);
                  if (result)
                  {
                      col1[i] = latitude;
                      Console.WriteLine("lat: " + col1[i]);
                  }
                  else
                  {
                      if (lat == null) lat = "";
                      Console.WriteLine("Attempted conversion of lat '{0}' failed.", lat);
                  }
                  bool result2 = Int32.TryParse(lng, out longitude);
                  if (result2)
                  {
                      col2[i] = longitude;
                      Console.WriteLine("longit: " + col2[i]);
                  }
                  else
                  {
                      if (lng == null) lng = "";
                      Console.WriteLine("Attempted conversion of lng '{0}' failed.", lng);
                  }

As a result it always excutes else condition and if i don't handle this exception in else condition then it gives "input string was not in a correct format in c# net int.parse" How to solve this problem ?

1
  • Well, they're not integers (they have decimals), so it's not exactly surprising. Did you really want to parse to integer? Commented May 25, 2015 at 9:37

1 Answer 1

3

You are passing in floating point numbers and using an integer parsing method.

Use the Double.Parse parsing method instead.

Sign up to request clarification or add additional context in comments.

1 Comment

@merling2011 thanks..i had bcme dumb bcz of headache..cudnt detect very simple thing :'(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.