Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for end of line index position in a string

Status
Not open for further replies.

rcavour

Technical User
Sep 21, 2006
9
0
0
US
Could someone tell me what I am doing wrong here. I have a function that takes a line string created by fgets and the script passes this string to my function Process_Info(see below). I need to extract the string from a fixed index location to the end of the line. I am having problems getting the index number of the end of line character (in this case a line feed).

Thank you.

Example:
Part # = 123456 Rev. RA M
Compat Code = 0x00000001

In both cases above, the info returned from Process_Info fuction should be "123456 Rev. RA M" or "0x00000001"; depending on the line I pass down.

func Process_Info : string
param string strLine

integer nEolPos, nLength
string strInfo

strchr strLine 0x0a nEolPos ;Look for the eol
nLength = nEolPos - 15 + 1 ;Length of data

;extracts the string in specified length
substr strInfo strLine 15 nLength

return strInfo

endfunc
 
If you are using the TEXT flag with the fopen command, then any carriage returns and linefeeds will be stripped from the string that you read from the text file.

 
You right. Once I started playing with the script I caught that the TEXT flag was stripping those characters. I was able to fix my fuction by using strlen instead of strchr and compensating for the 0-based index as such:

func Process_Info : string
param string strLine

integer nEolPos, nLength
string strInfo


strlen strLine nEolPos ; Look for the end of line position
nLength = nEolPos - 15 ; Length of data needed to be parsed
substr strInfo strLine 15 nLength ; extracts the string in specified length

return strInfo

endfunc

Thanks for the TEXT flag pointer! That was one of my problems.
 
Have you looked into using strright instead?

Code:
strright newString strLine 15

Where newString is will end up with your wanted data.
You'd have to adjust the # of characters returned based on which line you fed it.
 
Yeah that worked too when adjusting the data length. Thank you for the hints!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top