To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Oct 21st, 2006, 08:49 PM   #1
odamsr
Member
 
Join Date: Jun 03
Location: Georgia
Posts: 32
odamsr is an unknown quantity at this point (<10)
[2005] Search a string for ControlChars.CrLf

I am passing in a string using a streamreader. I am trying to find if a line uses CrLf, Cr, or LF. I have tried using an Instr but it always returns 0. What am I doing wrong? Should I be using something else?

VB Code:
  1. InStr(txtFileContents.Text, ControlChars.CrLf)

Thanks
Shannon
__________________
My Webpage
odamsr is offline   Reply With Quote
Old Oct 21st, 2006, 08:58 PM   #2
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 60,536
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: [2005] Search a string for ControlChars.CrLf

CrLf is a Windows line break, which consists of a carriage return and a line feed. If your string doesn't contain that combination then it can't be found. If your string only contains line feeds then you need to search for line feeds only. Line feeds on their own are used as line breaks on most other OSes, so Windows will normally treat them as line breaks too. Try this:
VB Code:
  1. Dim firstLineBreak As Integer = txtFileContents.Text.IndexOf(ControlChars.CrLf)
  2. Dim firstLineFeed As Integer = txtFileContents.Text.IndexOf(ControlChars.Lf)
  3. If firstLineBreak = -1 Then
  4.     MessageBox.Show("No line Windows line breaks")
  5. Else
  6.     MessageBox.Show("First Windows line break at " & firstLineBreak)
  7. End If
  8. If firstLineFeed = -1 Then
  9.     MessageBox.Show("No line line feeds")
  10. Else
  11.     MessageBox.Show("First line feed at " & firstLineFeed)
  12. End If
__________________

2007, 2008, 2009, 2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET
jmcilhinney is offline   Reply With Quote
Old Oct 21st, 2006, 09:12 PM   #3
odamsr
Member
 
Join Date: Jun 03
Location: Georgia
Posts: 32
odamsr is an unknown quantity at this point (<10)
Re: [2005] Search a string for ControlChars.CrLf

Thanks for the quick reply. You code worked great. My problem was I was using the sr.readline instread of sr.readtoend. We get fixed width files in from clients that are generated from a mainframe and they say they are CRLF and alot of times they use LF and our ETL tool needs to know what type so I trying to write an app that will check and put the correct line terminator in. Again, thanks for your help.

Shannon
__________________
My Webpage
odamsr is offline   Reply With Quote
Old Oct 21st, 2006, 09:38 PM   #4
Jumpercables
Fanatic Member
 
Jumpercables's Avatar
 
Join Date: Jul 05
Location: Colorado
Posts: 592
Jumpercables is on a distinguished road (20+)
Re: [2005] Search a string for ControlChars.CrLf

ReadLine() only reads the current line of the stream while ReadToEnd() reads the whole stream.
__________________

C# - .NET 1.1 / .NET 2.0

"Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
_____________________
Regular Expressions Library
Connection String
API Functions
Database FAQ & Tutorial
Jumpercables is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:56 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.