473,832 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I use InStr to find newline codes?

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!
Nov 21 '05 #1
5 6218
Dim s As String
s.IndexOf(vbCrL f & "02")
or
s.IndexOf(vbCr & "02")

Untested, but that should do it...
Chris

"Claud Balls" <Li**@trainer.c om> wrote in message
news:eC******** *****@TK2MSFTNG P15.phx.gbl...
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!

Nov 21 '05 #2
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
Nov 21 '05 #3
"Cor Ligthert" <no************ @planet.nl> 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/>
Nov 21 '05 #4
"Claud Balls" <Li**@trainer.c om> 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.Ne wLine & _
"20103" & ControlChars.Ne wLine & _
"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.Ne wLine & _
"20103" & ControlChars.Ne wLine & _
"030201"
For Each Line As String In Split(s, ControlChars.Ne wLine)
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/>
Nov 21 '05 #5
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.Visua lBasic.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
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6895
by: Graham Mattingley | last post by:
How do I use InStr to find the string d="1" I have tryed InStr(text,"d=&quot;1&quot;") and it does not work I have tryed a few other variations and I cant get it to work Thanks
6
2627
by: Joey Martin | last post by:
I have a script that looks for a phone number. I use an instr to see if it finds a - for the phone number. I them grab the 3 characters before and 4 after for the phone number. Works well, except when someone uses the - in the text. How can look for the second instance of the - if the right 4 characters past the - are not numeric? Thanks!
7
2864
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
5
24990
by: PJSimon | last post by:
Let's say I want to find the occurance of SearchString in MyString, but I want to search without regard to case ... Which is better and why in VB.Net? Index = Instr(MyString, SearchString) - 1 or Index = MyString.ToUpper.IndexOf(SearchString.ToUpper)
4
3921
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field. ie "McCarthy,John Doe Willy". I have to split up Familyname and the 1st FirstName. The FamilyName works perfect, just looking up the comma with InStr and use Left(). Now can someone throw me a bone to help me get the 1st Firstname. "John" according...
31
4435
by: RobertGabriel | last post by:
I am trying to find multiple entries that meet my criteria. this works great-- Work_Order: IIf(IIf(InStr(1,!,"200")>0,Val(Mid(!, InStr(1,!,"200"),9)))>200000000,Mid(!, InStr(1,!,"200"),9)) Example result = 200158687. My problem is this field has more than 1 number that I need to extract. My table format has 2 columns: named CRnum and Description. I need a record for each Work_Order ie: CRnum Work_Order.
1
4852
by: bolatito | last post by:
How can I make use of thisi ASP instruction in trying to restrict access to a page. If Instr(Request.ServerVariable(HTTP_REFERER),"pagename.asp") The pagename is the name of the page that containsn the form action. <% if Instr (Request.ServerVariables(HTTP_REFERER),"log") = "true" then response.write("INVALID USER")
6
2578
by: Brian | last post by:
what is the equivlant of the vb 6 instr I have a string there has "*D*N" I want to find the position that the D is in with a dotnet (VB) function
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10780
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10497
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.