Read through a string 1 char at a time ignoring CR & LF.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Baldrik
Junior Coder
Posts: 24
Joined: Mon Feb 14, 2005 11:11 pm
Location: TA7, UK

Read through a string 1 char at a time ignoring CR & LF.

Post by Baldrik » Mon Mar 07, 2005 10:13 pm

I'm reading through a string that contains an html page got by an Htt> command, and can't
work out how to find the next non-blank after positioning to certain text. I want to ignore CR
& LF characters since the non-blank is sometimes on the next line.

Effectively I want to code

if>%inputchar%=%cr%
...


but haven't been able to see how to get a CR character into the variable %cr%


There is an faq for "Read through a string one character at a time"
http://www.mjtnet.com/forum/viewtopic.php?t=1513 but it only deals with a single-line
string.


For example, I want to extract the date that starts with dayname from a web page
containing several other dates like this:


...Monday ...
... Tuesday ... April ...
Monday March 25
... December ...


or sometimes its like this

...tuesday...
Monday
March 25 .... December


To get to the dayname, I use

position>BR>Monday ,%page%,1,pos
if>%pos%=0
position>BR>Tuesday ,%page%,1,pos
endif
if>%pos%=0
position>BR>Wed...
...
endif


then want to do something like this to get a 3-char month for comparing with Jan/Feb/Mar to
turn into a
monthnumber...

if>%pos%>0
// have found the dayname so now find the blank after the dayname
position> ,%page%,1,pos
gosub>positiontonextnonblank // move pos to next non-blank somehow
midstr>%page%,%pos%,3,%monthname%
if>%monthname%=Jan
let>monthnum=01
endif
if>%monthname%=Feb
...


Can anyone help with what to code to put in a positiontonextnonblank subroutine?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Mar 08, 2005 2:35 am

No time to work on this right now, but two approaches come to mind.

1.You might want to look at using Regular Expressions. Macro Scheduler includes VB Script, and I think that VB Script does support RegEx. But I must advise, that if you have never used RegEx, it may appear daunting at first.

2. You may also want to use Macro Scheduler to open up a text editor like TextPad and use the Search/Replace with/without RegEx tools to get your results into a file that Macro Scheduler can then finish processing for you.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Mar 08, 2005 8:05 am

If you just want to remove all CR and LF characters just do this:

StringReplace>page,CR,,page
StringReplace>page,LF,,page

StringReplace was added in 7.3.10.5, see:
http://www.mjtnet.com/forum/viewtopic.php?t=1734
MJT Net Support
[email protected]

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Mar 10, 2005 3:53 am

Based on this code posted by support in another thread it appears that the operators can be used with characters. You may be able to use something like this code to find the position of the start letter of the month by replacing the char9 with char >= A char MyVal=3g5tmar61gg3

Let>k=0
Length>MyVal,lv
Let>NewVal=
Label>Trim
Let>k=k+1
if>k>lv,Done
MidStr>MyVal,k,1,char
If>charchar>9,Trim
ConCat>NewVal,char
Goto>Trim
Label>Done
Let>MyVal=NewVal

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts