locked
Input String RRS feed

  • Question

  • Guys

    I have the following code

    private async void Mainimage_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
            {
                var x = e.GetPosition(sender as Image).ToString();
                string[] cord = x.Split(new Char[] { ' ', ',', '\t' });
                var cordx = System.Convert.ToInt32(cord[0]);
                var cordy = System.Convert.ToInt32(cord[1]);

               StorageFolder storageFolder = KnownFolders.PicturesLibrary;
    StorageFile sampleFile = await storageFolder.GetFileAsync("Data.dat");
    try
     {
     if (sampleFile != null)
     {
             var readLine = await FileIO.ReadLinesAsync(sampleFile);
    foreach (String i in readLine)
    {
    string[] Split = i.Split(new Char[] { ',' });
        pageTitle.Text = Split[0] + " : " + Split[6] + " : " + Split[7] + " : " + Split[8] + " : " + Split[9] + " : ";
        var x1 = System.Convert.ToInt32(Split[6]);
        var x2 = System.Convert.ToInt32(Split[7]);
        var y1 = System.Convert.ToInt32(Split[8]);
        var y2 = System.Convert.ToInt32(Split[9]);
        if ((cordx > x1 & (cordx < x2)))
        {
            if ((cordy > y1 & (cordy < y2)))
            {
                this.Frame.Navigate(typeof(roomdata),Split[0]);
            }
        }
        }

    I loads a string deliminated by commas and splits it into 9 parts

    I am trying to compare 4 coordinates in Split 6 - 9 against the actual coordinates from the double tap event (Cord x & Y)

    the values are all strings and are as follows

    CordX = 330.112 (This is the actual X coordinate of the tap)

    CordY = 220.0 (This is the actual Y coordinate of the tap)

    X1 = 3.0 (this is the left X coordinate of a rectangle)

    X2 = 3.0 (this is the right X coordinate of a rectangle)

    Y1=3.0 (this is the left Y coordinate of a rectangle)

    Y2 = 3.0 (this is the Right Y coordinate of a rectangle)

    (I have used 3,3,3,3 as a temp coordinates until I map the whole image then all 4 will be different)

    When I run it I get a "Input string was not in correct format" error

    All strings are converted to double 

    I cant get my head around what is wrong

    Any ideas

    Mark

    Wednesday, November 20, 2013 10:59 PM

Answers

  • in the .dat there is this line: 0042,Harris Academy Morden,1st Floor,B Block,"Preparation Room, 1St Floor",B/F/R/2,3,3,3,3

    when you split this on the , the 6 entry will be B/F/R/2 which cant be converted to an double


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by wambaugh1 Saturday, November 23, 2013 7:11 AM
    Thursday, November 21, 2013 9:41 AM

All replies

  • what is in the Data.dat file?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, November 20, 2013 11:10 PM
  • i think you have to edit your second line:

    string[] cord = x.Split(new Char[] { ' ', ',', '\t' });

    into this:

    string[] cord = x.Split(new Char[] { ' ', ',', '\t', ';' });


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, November 20, 2013 11:21 PM
  • Hi

    data.dat is a CSV text file it has 1295 line each line containing 9 strings deliminated by a comma

    Mark

    Thursday, November 21, 2013 12:00 AM
  • Hi

    I tried this but give exactly the same error

    when I press break and hover over the values of the variables it has the exact values as described in my post so I know it is reading the values from the text file and I know that cord x&y have the actual coordinates of the tap in

    all are converted to double so I really cant figure it out

    Mark

    Thursday, November 21, 2013 12:03 AM
  • which line the exception happens?

    can you share one line out the file so i can try here?

    or have a project that we can run?

    i was getting the format exception alraedy at the thirth line because you missed the ; in the split.


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Thursday, November 21, 2013 12:10 AM
  • I Get the exception on the line

    var x1 = System.Convert.ToDouble(Split[6]);

    I added the following line

     var y22 = System.Convert.ToDouble(Split[0]);

    this is the unique identifier for each line in the text file

    The variable when hovered on says 41 which says to me that the loop is working ok for the first 40 lines and then falling over

    the format of the line in the data.dat file is

    0041,Harris Academy Morden,1st Floor,B Block,Science 3,B/F/R/1,3,3,3,3

    it is saved from notepad in unicode format

    mark

    Thursday, November 21, 2013 12:24 AM
  • My project is on my skydrive as a zip file

    https://skydrive.live.com/redir?resid=1B8C1CB2EA1F9BF7%21125

    Mark


    Thursday, November 21, 2013 12:28 AM
  • in the .dat there is this line: 0042,Harris Academy Morden,1st Floor,B Block,"Preparation Room, 1St Floor",B/F/R/2,3,3,3,3

    when you split this on the , the 6 entry will be B/F/R/2 which cant be converted to an double


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by wambaugh1 Saturday, November 23, 2013 7:11 AM
    Thursday, November 21, 2013 9:41 AM
  • Thank you there was a couple of others as well but it works

    It has however show a second problem

    because of all the converting from string to double the unique identifier has had the leading zeros striped out so I cant compare them.

    if (roomname.Equals(Split[0])) (This compares roomname with Split[0])

    roomname is the one that has been stripped. 

    Example

    roomname = 143

    Split[0] = 0143

    how do I make roomname = 0143

    i though i could get the lenght of roomname and if it = 3 the add one 0 to the beginning if it = 2 the ad 2 zeros and so on

    I keep getting cant convert int to bool errors

    any ideas?

    Mark

    Thursday, November 21, 2013 9:15 PM