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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I test for hex 0C 0D in my text file?

Status
Not open for further replies.

tbtcust

Programmer
Oct 26, 2004
214
US
Hi all. I have a text file that has what I think is hex 0C 0D. I'd like to strip them out. How can I test for hex 0C 0D in my text file?

Thanks in advance for any help
 
Chr Hex0C is the printer linefeed character and Hex0D is the carriage return needed to print a new line. Its always there wherever you have typed the enter key.

The INSTR function searches for any characters in a string and returns it's position in the file, then you could use Left() and Mid() to get the string up to the chrs and the part after it and recombine them. If more than one set of OC CD's then loop until none found

Dim StartPos as Integer,ChrPosn as Integer
StartPos=1
ChrPosn=1
Do while ChrPosn > 0 'keep looking until none found
ChrPosn = INSTR(StartPos,MyString,(Chr(&h0C) & Chr(&h0D)))
MyString=Left(MyString,ChrPosn-1) & Mid(MyString,ChrPosn+2)
StartPos=ChrPosn + 2 'look ahead for more
Loop
 
Thanks for the explanation and code tedsmith. This solution works well.
 
There's still some misinformation here: hex 0C is NOT line-feed, it's form-feed. Line-feed is hex 0A, and CRLF is hex 0D0A, not the other way around.

Either the OP was wrong about the characters in his file, or he doesn't have a straight text file; could be some document format.
 
vbFormFeed is an intrinsic constant, as is vbCr. There is no need for Chr(<hex value>) operations.
 
Yes, I didn't realise Replace could handle multiple occurrences in the same string.

Hex 0C is VBFormFeed
Hex 0D is VBCr
You can't combine them to VbFormFeedCr

The chars in Replace method would have to be:
strIN = Replace(strIN, (vbFormfeed & VbCr), "")

They may be printer control codes for a new page.
 
Thanks everyone for your help.

Also, I use a hex editor/viewer and confirmed that hex 0C 0D is in my text file.

Thanks again.
 
it is ge3nerally better to replace whitespace characters (e.g. CR; LF; FF) with a space than "Nothing". Replacing them with nothing leave hte previous and next characters jammed together, making reading hte file (by people anyway) much more taxing. Leaving the space in place of the whitespace leaves it more (humanly) readable




MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top