This is the type of code I use to strip comments in basic that
can have quoted text that has the character " ' " in it. I generally
inline code of this type to save stack overhead but the concept
is simple enough, just test which is the furthest right, if its a
quote, the character is in the string, if its not, its a comment.
Regards,
[email protected]
------------------
can have quoted text that has the character " ' " in it. I generally
inline code of this type to save stack overhead but the concept
is simple enough, just test which is the furthest right, if its a
quote, the character is in the string, if its not, its a comment.
Regards,
[email protected]
Code:
LOCAL qvar as LONG LOCAL cvar as LONG LOCAL src as LONG LOCAL lnth as LONG a$ = "test$ = "+chr$(34)+" 'Basic comments' "+chr$(34)+" ' comment" lnth = len(a$) src = StrPtr(a$) ' ========================= ! mov esi, src ! xor ecx, ecx ! xor edx, edx lblx: ! mov al, [esi] ! inc esi ! inc ecx ! cmp al, 34 ; quote ! jne nxtlblx ! mov edx, ecx nxtlblx: ! cmp ecx, lnth ! jne lblx ! mov qvar, edx ' ========================= ! mov esi, src ! xor ecx, ecx ! xor edx, edx lbly: ! mov al, [esi] ! inc esi ! inc ecx ! cmp al, "'" ; comment ! jne nxtlbly ! mov edx, ecx nxtlbly: ! cmp ecx, lnth ! jne lbly ! mov cvar, edx ' ========================= ' ================================================== ' if last comment position is > last quote position ' then it is a comment and not a part of a string ' ================================================== If cvar > qvar Then a$ = rtrim$(left$(a$,cvar-1)) End If MessageBox hWin,ByCopy a$,ByCopy str$(qvar)+" "+str$(cvar), _ %MB_OK or %MB_ICONINFORMATION
Comment