Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find & Replace, Variables in text questions
#1
Your help has been great, learned quite a bit in the last couple of days (and registered today to boot ; )

I'm stuck in these (hopefully) last two areas:

------------------------
I. In a simple text block (html template) whether stored internally in QM or in an external text file, I need to:

a) Place two earlier-defined variables (say "en" and "fn" respectively) into one spot each within the text/code-to-be -- one as simple text on the page ( Event Name - str ev) and the other into the middle of a link (File Name - str fn) . Excerpt example, this is were "fn" would go:

<a href="http://nonprofit.org/mediafiles/REPLACE_THIS_BIT_WITH_fn">right-click to download</a>

b) Then I need to know how/where to get the resulting output of the template with changes (I believe I can figure out the renaming/saving/uploading from there...)

---------------------------
II. I need to also put those exact same two variables along with preceding and following plain text into the body of an email (plus a third existing variable "em" into the "TO" field) to send out an auto notification with the Event Name and HTML link to the above created page. The MailTo: stuff and variables/expressions is easy, but...

I just can't seem to grasp using variables within text fields/blocks. Obviously I. and II. are related to my same mental block. My little VB programming doesn't seem to translate here and I haven't found any clear examples of what I need via search. I came close with format fields, but always lost it somewhere along the way.

Your help is much appreciated,

Steve

P.S. I am aware mailto: probably isn't the best method in general, but it was easy gratification and this will be used on one or two fixed workstations max, not on the web etc.

edit: disabled html for code example
#2
i don't have a lot of time but i can get you started.

for mailto info you can also see my blog
http://themacrohook.blogspot.com/search/label/mailto

for findreplace info see here as well
http://themacrohook.blogspot.com/2007/0 ... heory.html

there's also a method of creating a string value with more than one line in there as well which can help with long multi-line string values.

if you want to put a string inside another at a certian spot do it just like you have it above.

Code:
Copy      Help
str a=
;stnhnh htnseoah
;stnh tnuseoaht htoensa
;snth htnue hots ho put it here htnuesoats htenosa


a.findreplace("put it here" "replaced text")
out a


in fact my whole article on String Theory should answer a lot of your questions.
An old blog on QM coding and automation.

The Macro Hook
#3
i.
Simplest replacement
Code:
Copy      Help
str template en fn

;lets create template text for testing. Normally you would probably use template.getfile("...").
template=
;...
;... <a href="http://nonprofit.org/mediafiles/{FN}">{EN}</a> ...
;...


;set fn and en
fn="filename.jpg"
en="right-click to download"

;replace
template.findreplace("{FN}" fn)
template.findreplace("{EN}" en)

out template

;{EN} and {FN} here used as examples of placeholders for variables in the template.

Replacement using regular expressions
Code:
Copy      Help
str template en fn

;lets create template text for testing. Normally you would probably use template.getfile("...").
template=
;...
;... <a href="http://nonprofit.org/mediafiles/{FN}">{EN}</a> ...
;...


;set fn and en
fn="filename.jpg"
en="right-click to download"

;Replace text in template. Use regular expression.

;to make more clear, I at first store the regular expression to rx variable and give some explanations
str rx="(<a href=''http://nonprofit.org/mediafiles/)\{FN\}''>\{EN\}</a>"
;\;- used to escape { and } because they are special characters in regex syntax
;() - used to mark parts of text
;Here '' is used for ". It is not part of regular expression syntax.


;the replacement must contain variables, therefore we need to format it at first
str repl.format("$1%s''>%s</a>" fn en) ;;replaces %s to values of fn and en. Regex specific: $1 represents the enclosed part

;now replace
template.replacerx(rx repl 1)

out template

;In real world, the regular expression should be more sophisticated, eg use \s instead of space (because it may be line break)

;{EN} and {FN} here used as examples of placeholders for variables in the template.

ii.
Hope the above will help with it.
#4
Thank you Ken and Gintaras!

Ken - it figures that I came across your excellent blog while at work back in late April-ish. I went thru the lessons you had at the time (I think 1-3?), which gave me a real leg up and planted the seeds of the project on which I am now working.

I've just picked back up again with the proj. in earnest over last weekend, but spaced your blog until just the other day (thinking your lessons were part of the forum here, duh...).

Anyway, in the brief read I've had, both of your tips seem clear and I will post back once I've had a chance to work on Macro del Diablo this evening (just off to work right now...).

Thanks again -- With your pointers, I think I may become a productive member of the QM society one day...

Cheers,

Steve
#5
Worked like a charm, thanks guys.


Forum Jump:


Users browsing this thread: 1 Guest(s)