PC Review


Reply
Thread Tools Rate Thread

Can I use InStr to find newline codes?

 
 
Claud Balls
Guest
Posts: n/a
 
      11th Mar 2005
if I read the following into a variable:

010203
020103
030201

could I use something like instr(variable,/n & "02")
to return the position where 02 starts the line?





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      11th Mar 2005
Dim s As String
s.IndexOf(vbCrLf & "02")
or
s.IndexOf(vbCr & "02")

Untested, but that should do it...
Chris

"Claud Balls" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> if I read the following into a variable:
>
> 010203
> 020103
> 030201
>
> could I use something like instr(variable,/n & "02")
> to return the position where 02 starts the line?
>
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      11th Mar 2005
Claud,

In addition to Chris, although I never use it, is there as well a
Visual.Basic Function "Left".

Which can be used in a for loop, it describes in this case in your program
probably better what you are doing..

http://msdn.microsoft.com/library/de.../vafctleft.asp

I hope this gives some more ideas.

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Mar 2005
"Cor Ligthert" <(E-Mail Removed)> schrieb:
> In addition to Chris, although I never use it, is there as well a
> Visual.Basic Function "Left".


How do you use 'Left' as a replacement for 'InStr'?!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Mar 2005
"Claud Balls" <(E-Mail Removed)> schrieb:
> if I read the following into a variable:
>
> 010203
> 020103
> 030201
>
> could I use something like instr(variable,/n & "02")
> to return the position where 02 starts the line?


Yes.

If you want to read the strings line-by-line, you can use 'StringReader':

\\\
Imports System.IO
..
..
..
Dim s As String = _
"010203" & ControlChars.NewLine & _
"20103" & ControlChars.NewLine & _
"030201"
Dim sr As New StringReader(s)
Dim Line As String = sr.ReadLine
Do While Not Line Is Nothing
MsgBox(Line)
Line = sr.ReadLine()
Loop
///

Alternatively you can split the string:

\\\
Dim s As String = _
"010203" & ControlChars.NewLine & _
"20103" & ControlChars.NewLine & _
"030201"
For Each Line As String In Split(s, ControlChars.NewLine)
MsgBox(Line)
Next Line
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      12th Mar 2005
Herfried,

>
> How do you use 'Left' as a replacement for 'InStr'?!
>

I think thought that you are smart enough to see how when you look at the
question from the OP again, however to make it easy for you. (I used a
string array, I dont know what is the format of the OP, however it goes with
any other type of course as well).

\\\
Dim str As String() = {"010203", "020103", "30201"}
For i As Integer = 0 To str.Length - 1
If Microsoft.VisualBasic.Left(str(i), 2) = "02" Then
MessageBox.Show("line " & i.ToString & " starts with 02")
exit for
End If
Next
///

Nothing wrong, I miss them myself as well sometimes and than I think it is
better to ask than to misunderstand.

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using InStr to find a range of ASCII characters Albert S. Microsoft Access 7 14th May 2010 01:02 AM
Use InStr to find Excel carriage return =?Utf-8?B?SnVkeSBXYXJk?= Microsoft Access Queries 4 4th Nov 2007 03:44 PM
How do I find quotation marks in a string using INSTR? String exa. =?Utf-8?B?R3JhbmRwYSBCZXJuaWU=?= Microsoft Access Queries 2 3rd May 2006 09:53 PM
Re: Find number of spaces in a string (instr) DejaVu Microsoft Excel Programming 0 12th Sep 2005 09:40 PM
is there an equal fxn for 'InStr' in excel. Not Find or Search =?Utf-8?B?Q2xhdXNpdXM=?= Microsoft Excel Worksheet Functions 2 30th Jun 2005 08:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.