find first character of line

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Snickers76
Newbie
Posts: 12
Joined: Mon Mar 10, 2008 6:26 pm

find first character of line

Post by Snickers76 » Wed May 28, 2008 8:20 pm

I have a text file that contains data I need to insert into an Excel file.
I have found a way to search for the specific starting line of my data; however, I need to find a way to detect the final line of data.

This is what a few lines of my data would look like:

#0001: Job description 01/19/08
Step 1: do this 01/22/08
Step 2: do this after 01/24/08
Step 3: do this after after 01/29/08
#0002: Job description 02/19/08
Step 1: do this 02/22/08
Step 2: do this after 02/24/08
Step 3: do this after after 02/29/08
#0003: Job description 03/19/08
Step 1: do this 03/22/08
Step 2: do this after 03/24/08
Step 3: do this after after 03/29/08

For example, I can already find job number 0002. What I want to do is send to excel cell number R1C1 all data between #0002 and the final date.

How can i find the line that the next "#" symbol starts on? If I know the line number that the next "#" symbol starts on, I can then store and combine each line after #0002 in a variable but stop before getting to the next job description #0003.

How can i find the line that the next "#" symbol starts on?
Is there an easier way?

The job numbers are NOT sequential.

may return my starting character, yes?
MidStr>

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 28, 2008 8:33 pm

So just loop through the file combiningg each line until you find a line beginning with a #. At that point send the combined lines to Excel, reset the output var and continue. Like this:

Code: Select all

ReadFile>d:\jobs.txt,inFile
Separate>inFile,CRLF,lines

Let>k=0
Let>combined=
Repeat>k

  Let>k=k+1
  Let>this_line=lines_%k%

  Position>#,this_line,1,p
  If>p=1
    //found line starting with #,

	If>combined<>
      //output combined to Excel .. but use a messagemodal here as example
	  MessageModal>combined
	Endif

	//reset combined
	Let>combined=
  Else
    Let>combined=%combined%%this_line%
  Endif

Until>k=lines_count
This particular example will output the combined lines for job1, then job2 and then job3.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Snickers76
Newbie
Posts: 12
Joined: Mon Mar 10, 2008 6:26 pm

Post by Snickers76 » Thu May 29, 2008 11:55 am

I have a couple more questions if you don't mind answering them.
After all of the lines have been combined into a single line of text, such as the above code does, is it possible to enter soft returns that will simulate the ALT-ENTER that is in excel. I would like to have a crlf in between each line for excel but the crlf doesnt seem to work.


Is it possible for macro scheduler to convert a .pdf document to a text file?

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Thu May 29, 2008 6:22 pm

Is it possible to grab the last 8 characters of text from a predetermined line?

to be more specific, for example:

#0001: Job description 9/19/07 10/29/08
Step 1: do this 9/19/07
Step 2: do this after 10/24/08
Step 3: do this after after 10/29/08

Once I know what line #0001 exists on, is there a way to store only the last 8 characters, the finishing date, into a variable?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu May 29, 2008 6:36 pm

Once you have the line in a variable use length> to get the length (number of characters in the line). subtract 7 from the length. then use the result in a MidStr>

///(assuming the line is in variable "line")
Length>line,len
Sub>len,7
Midstr>line,%len%,8,LastEight

MDL>LastEight

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Thu May 29, 2008 8:06 pm

JRL wrote:Once you have the line in a variable use length> to get the length (number of characters in the line). subtract 7 from the length. then use the result in a MidStr>

///(assuming the line is in variable "line")
Length>line,len
Sub>len,7
Midstr>line,%len%,8,LastEight

MDL>LastEight
Thats great. Works like a charm. Thank you much, JRL for that snippet.

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