problem with text editing.

About Monkey 2 Forums Monkey 2 Development problem with text editing.

This topic contains 6 replies, has 3 voices, and was last updated by  Jesse 2 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #4058

    Jesse
    Participant

    I am trying to load a text file and parse it byte by byte, I can brake it down into lines and display it correctly but when I try to parse it by bytes and add the bytes back up it creates some weird text at the end of each line. I think its a problem with the byte additions in the string class but I need to verify. I have included the text file with a “fnt” extension. And the source code is a small test program:

    [/crayon]

    this is a link to this same source code and text file:
    https://www.dropbox.com/s/n0qiv91gxuqg3l1/Archive.zip?dl=0

    I would appreciate if someone could give me a hand in figuring this out.

    #4059

    AdamStrange
    Participant

    not sure what the issue is, as far as I could see the .fnt file looks ok. But the code is a bit mangled.

    Here’s a simpler version which reads the file byte by byte and reconstructs each line. gives a very different output:

    #4064

    Jesse
    Participant

    did you download and run the code?
    your code doesn’t do what I want to do.

    the problem with my code is that it reads the line and outputs the result but at the end of the line it adds some extra characters, characters that are not in the text file. the picture shows that the last 5 or four characters at each of the lines are extra:
    image
    if you compare the output with the txt file you will notice that it does not contain “{char” at the end of each line of the “.fnt” file.

    if I replace line 27 with this:
    s += lines[i].Mid(j,1)
    it works fine.

    #4075

    Mark Sibly
    Keymaster

    You’re reading past the end of line, you need something like:

    But mx2’s not helping here – it should be generating something like ‘index out of range’ when you try to do this. Will fix ASAP.

    #4076

    Jesse
    Participant

    Thanks.

    about reading past the end of the line,it’s not.
    if I replace line 27:
    s += String.FromChar(lines[i][j])
    with this:
    s += lines[i].Mid(j,1)
    it works fine.

    #4077

    Mark Sibly
    Keymaster

    Your first while loops compares char at j with 32, without first checking that j<line.Length. With char index checking on, it indeed fails here on the first line of the text file.

    Your second while loop is better, but it checks j<line.length *after* reading char at j so the check is too late.

    it works fine.

    This is because Mid() uses Slice, which does a range check so it’ll be returning an empty string once you go past end of line. Here, it works for a bit longer with this change but I eventually get a ‘memory access error’.

    String char index checking would have made this 100 times easier to find (can’t believe it wasn’t there – sure it used to be), so it’s my fault really…

    #4078

    Jesse
    Participant

    As usual I feel stupid. I still don’t get why it goes beyond one and not with the other. I don’t see why the while don’t exit if j >= to line[i].Length. to my understanding it should exit regardless of what follows. Don’t worry i am known to have this kind of moments.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.