im just looking for some really good ideas on how to trim trailing spaces from lines in an editbox/richedit controls. please post some suggestions.
Posted on 2002-06-13 22:15:10 by smurf
Does this feature, same as UltraEdit? Or not?

For example if i have a string like this(where blue colored x's are the trailing spaces):

::Ultraedit Feature::

HelloxxCruelxxxWorldxxxx

For this one, just take a line of text from the edit control and place it in a buffer, use strlen(preferably the MMX ones). Start looking for 20h from the last character of the string going to the first character:

HelloxxCruelxxxWorldxxxx <- start at the last char going left until you hit a non space character. Using this example, you'll stop at d. Append a newline(0Dh, 0Ah) after d.

Select the line of text using EM_SETSEL and replace it using EM_REPLACESEL


::Non - Ultraedit Feature::

HelloxxCruelxxxWorld

For the 2nd one, this might be tedious since you have to shift the number of spaces depending on the number of trailing spaces.

Using this example: HelloxxCruelxxxWorld

for the first occurance of trailing spaces(HelloxxCrue...) Shift 1 place to the left.

for the second occurance of trailing spaces(CruelxxxWorld) Shift 2 places to the left.

Shifting characters involves all the characters from the right starting at an occurance of trailing spaces.

When done use EM_SETSEL and EM_REPLACESEL combo...

:)
Posted on 2002-06-13 22:40:05 by stryker
smurf,

The "rtrim" algo in the MASM32 lib is not a bad place to start but the action in what you are doing is how you retrieve the text in the first place.

If you pull it line by line, this approach will work but if you get the text in a block, you will have to scan through it backwards to remove the spaces after the ascii 13 character.


x = space character
this is normal text with spaces after itxxxxxx13,10.

scan it backwards and when you find the ascii 13, start stripping the following spaces.

Regards,

hutch@movsd.com
Posted on 2002-06-13 22:53:22 by hutch--

start stripping


now that is called taking something out of context :)
Posted on 2002-06-13 23:07:12 by jademtech
Hi smurf

Here is a simple algo.

KetilO
Posted on 2002-06-14 03:57:04 by KetilO
Hi smurf

The algo had a little bug. If last line did tot have CR+LF
it would leave a space at the end.

Here is the fixed algo:

SpaceTrim proc uses esi edi,lpBuff:DWORD


mov esi,lpBuff
mov edi,lpBuff
xor edx,edx
xor eax,eax
mov ah,0Ah
@@:
lodsb
.if al==' '
mov edx,1
.else
.if edx && al && al!=0Dh && ah!=0Ah
mov byte ptr [edi],' '
inc edi
.endif
stosb
mov ah,al
xor edx,edx
.endif
or al,al
jne @b
ret

SpaceTrim endp


KetilO
Posted on 2002-06-14 04:07:35 by KetilO
hi guys,

thanks for the idea's. ive been messing around with what stryker suggested and its working pretty good i just need to work out a few bugs. im just doing all this for learning experience.

KetilO: i had already tried the same approach as your code example and im impressed that your code does so much more with very little code compared to what i have. thanks for sharing im gonna compare the two different ways once i get them running like i want.
Posted on 2002-06-14 09:20:16 by smurf