lreplace count?

3 views
Skip to first unread message

Fred H Olson

unread,
Apr 13, 2013, 12:53:29 PM4/13/13
to Semware
Is there a way to get a number of replacements lreplace() made in a
macro without without having it ( option "1") in a loop with a
counter?

I checked and the "non-zero" that it returns seems to be "1"
no matter how many (more than 0) replacments are made.

Fred

--
Fred H. Olson Minneapolis,MN 55411 USA (near north Mpls)
Email: fholson at cohousing.org 612-588-9532
My Link Pg: http://fholson.cohousing.org My org:
Communications for Justice -- Free, superior listserv's w/o ads

knud van eeden

unread,
Apr 13, 2013, 1:14:05 PM4/13/13
to sem...@googlegroups.com
The current design is that LReplace() returns
1 if successful replaced
otherwise 
0.

But to get a fixed number of replacements made, you can
add the integer within the LReplace() options.

E.g.

PROC Main()
 Warn( LReplace( "a", "b", "ngi10" ) )
END

will replace "a" by "b" only 10 times.

E.g.

PROC Main()
 Warn( LReplace( "a", "b", "ngi3" ) )
END

will replace "a" by "b" only 3 times.

with friendly greetings,
Knud van Eeden





From: Fred H Olson <fho...@cohousing.org>
To: Semware <sem...@googlegroups.com>
Sent: Saturday, April 13, 2013 6:53 PM
Subject: [TSE] lreplace count?
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Larry

unread,
Apr 13, 2013, 1:28:14 PM4/13/13
to sem...@googlegroups.com
// jiglrepl.s - see how many lreplacements

<ctrlshift x> execmacro("jiglrepl")

proc main()

integer n=0

loop

if lreplace("the","eht","ing1")
n=n+1
else
goto ending
endif
if keypressed() goto ending endif
endloop

goto ending
ending:

warn("Changes: "+str(n))

end
--

---
You received this message because you are subscribed to the Google Groups
"SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to semware+u...@googlegroups.com.

Fred H Olson

unread,
Apr 13, 2013, 1:58:44 PM4/13/13
to sem...@googlegroups.com
Thanks Knud, I did not recall that a number other than "1" could be used.

Larry, something like your 'jiglrelp.s' was what I was thinking as a
workaround tho I had not written it. It seems like TSE probably has "n"
internally (since Replace() reports it) and a way to access it would
avoid the loop. Reporting it as the true flag would have been handy.

> if keypressed() goto ending endif
is interesting. You must have tried to replace a tremendous number of
strings at some time. I dont recall having time to press a key once a
replace was excecuted.

Larry

unread,
Apr 13, 2013, 2:56:01 PM4/13/13
to sem...@googlegroups.com
// jiglrepl.s - see how many l
/***
Assuming you might want to use the number of the number of replacements
itself in the macro, I used this method is a couple of my macros. Using
Replace() in a macro instead of lReplace(), you get the number of
changes placed on the statusline and read it into a variable to be used
by the macro.

For it to work properly, of course, you have to make sure you read the
statusline immediately after the Replace() and before the statusline is
updated.
***/

replacements

<ctrlshift x> execmacro("jiglrepl")

proc main()

string s[20]=""
integer n=0

replace("the","eht","ing")
getstrxy(1,query(statuslinerow),s,10)
n=val(s)

warn("Changes: "+str(n))

end

-----Original Message-----
From: Fred H Olson
Reply all
Reply to author
Forward
0 new messages