Hello everyone,
I'm trying to empty the Linefeed charachter from a string
The code compiles & runs fine. I have ran it in a debugger to see if it worked correctly, and it did
A bit further in my code I have a message box, that is to output my string to the screen, but the message box is empty
Here's the code I'm using:
xor esi, esi ; empty our counter
NCLRF:
cmp [buffer + esi], 10d ; check for a CRLF charachter
je Rmove ; if we find own replace it with a 0
inc esi
cmp esi, sizeof buffer ; compare our counter with the size of our buffer
jne NCLRF ; they don't equal? then do all this stuff again
invoke MessageBox, 0, addr buffer, addr capt, MB_OK
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
;buffer is ready to have a PRVMS: command appended to it (no \n left)
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
jmp loopspt ; jump back to our main loop
Rmove:
mov [buffer + esi], 0 ; place a 0 in the buffer
inc esi ; increment our counter
jmp NCLRF ; back to the loop
Could someone please tell me what I'm doing wrong and how to fix it, it might be a verry stupid mistake, since I'm very tired atm but I don't want to stop coding :toothy
Why are you placing 0 instead of \n :D ? It's a string terminator. If you really want to get rid of \n characters, you'll have to shift the buffer by one character (assuming it's only \n not \r\n) backwards when \n is found or at least put space character for a start.
Quote from: ramguru on October 23, 2010, 06:03:20 PM
Why are you placing 0 instead of \n :D ? It's a string terminator. If you really want to get rid of \n characters, you'll have to shift the buffer by one character (assuming it's only \n not \r\n) backwards when \n is found or at least put space character for a start.
Wa? 0's.... 0's a... string terminator? "-_-
*gets some coffee*No stricke that
*Gets a dubble coffee*Yea, now we're talking
But with what should I replace it them? I mean I have more data following that \n character, I cannot shift my buffer...
How would you go about it?
edit:Ok, I've replaced the 0 with a 1, and that seems to be working, but are there any better ways of doing this?
Quote from: SCHiM on October 23, 2010, 06:07:50 PM
edit:
Ok, I've replaced the 0 with a 1, and that seems to be working, but are there any better ways of doing this?
:bdg :lol :U :green
Space character, you know: mov [buffer + esi], ' '
Or you could have, say, two buffers:
Buffer1 the source buffer
Buffer2 the one that you copy everything to except \n characters
So you wouldn't need to replace anything
Quote from: ramguru on October 23, 2010, 06:16:08 PM
:bdg :lol :U :green
Space character, you know: mov [buffer + esi], ' '
Or you could have, say, two buffers:
Buffer1 the source buffer
Buffer2 the one that you copy everything to except \n characters
So you wouldn't need to replace anything
:dazzled:
*Tired-O-meter: spikes*
I must really be half asleep to not have though about using a space :eek
Anyways, I thank you
It's working now
As for the 2nd method, I don't know before hand how big my buffer is going to be
I know it will be less then 1kb big but creating 2 buffers 2 kb's big while most of the time only 100 or 200 bytes are going to be used is a waste :P
Use two pointers to the same buffer, only advance the second if you copy a non CR/LF character.
strloop:
mov al,[esi]
or al,al
jz done
cmp al,0Ah
jz strloop
mov [edi],al
inc edi
jmp strloop
done:
Also you might want to check for NUL characters in the input stream if the string does not fill the entire buffer.
Quotestrloop:
mov al,[esi]
or al,al
jz done
cmp al,0Ah
jz strloop
mov [edi],al
inc edi
jmp strloop
done:
I would modify this a bit to insure the terminating 0 is also copied at the end of the modified string:
strloop:
mov al,[esi]
cmp al,0Ah
jz strloop
mov [edi],al
inc edi
or al,al
jnz strloop
;done
You normally write code like this to change CRLF delimited text to wordwrap format and you do it by testing for both 13 and 10 in a collector loop and on exit write 1 space. If you don't want 1 trailing space you test the last byte written and if its ascii 32 (a space) you decrement the write pointer by 1 and write the terminating zero at that location.