The MASM Forum

General => The Campus => Topic started by: peter_asm on May 13, 2014, 11:46:07 AM

Title: FORC / problem with spaces in string
Post by: peter_asm on May 13, 2014, 11:46:07 AM
I've tried to process a string using FORC but for whatever reason, it stops after encountering a space in the string.
Is there a way around this limitation? I've tried to use @SizeStr in combination with @CatStr but still having problems then to identify if quote is in the string.


STRING_MACRO macro s:req
  FORC c, s
    %ECHO c
  ENDM
ENDM

STRING_MACRO "this is the string"


When compiling this, console displays

"
t
h
i
s


What I'd like to have is an if statement to determine what character is in the string like: if (c ne '"')
Title: Re: FORC / problem with spaces in string
Post by: qWord on May 13, 2014, 12:02:57 PM
In the FORC-line, s must be enclosed in angle brackets:
position = 1
FORC c, <s>
IFIDN <c>,<!">
%echo Position: @CatStr(%position)
ENDIF
position = position + 1
ENDM

If you want to check whether the parameter s holds any quote, simply use @InStr() or INSTR:

position INSTR <s>,<!">
IF position
% echo Position: @CatStr(%position)
ENDIF
; or 
IF @InStr(1,<s>,<!">) NE 0
% echo Position: @InStr(1,<s>,<!">)
ENDIF


EDIT: for more details, see MASM's Programmers Guide (http://remixshare.com/download/w3mwr), Chapter 9.
Title: Re: FORC / problem with spaces in string
Post by: peter_asm on May 13, 2014, 12:27:35 PM
Thanks qWord! got it working.