Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Searching a String


Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2003, 11:16 PM
KummaZ KummaZ is offline
Centurion
 
Join Date: Apr 2003
Posts: 162
Default Searching a String


I need help searching a string. I have a line at the top of the text file that I read into a string. I need to see if this line has two #'s at the front and if so to place whatever is after that and before the next 2 #'s. Thanks to anyone who can help me.
Reply With Quote
  #2  
Old 08-18-2003, 11:36 PM
ashish908 ashish908 is offline
Contributor
 
Join Date: Feb 2002
Location: Mumbai, India
Posts: 470
Default

To to get the position of the first occurence of "##" in the string str1
pos1 = Instr(str1,"##")

To get the position of the second occurence of "##" in the string str1 use-
pos2 = Instr(pos1,str1,"##")

Then you can extract the characters between pos1 and pos2 which will constitute the desired string
__________________
Success comes from knowing that you did your best to become the best that you are capable of becoming.
--John Wooden
Reply With Quote
  #3  
Old 08-18-2003, 11:41 PM
KummaZ KummaZ is offline
Centurion
 
Join Date: Apr 2003
Posts: 162
Default

Quote:
Originally Posted by ashish908
To to get the position of the first occurence of "##" in the string str1
pos1 = Instr(str1,"##")

To get the position of the second occurence of "##" in the string str1 use-
pos2 = Instr(pos1,str1,"##")

Then you can extract the characters between pos1 and pos2 which will constitute the desired string



thanks for that but how would I be able to extract that information from the string? could you please give me an example. thanks for your help.
Reply With Quote
  #4  
Old 08-19-2003, 12:12 AM
J0n J0n is offline
Junior Contributor
 
Join Date: Jun 2003
Location: Australia
Posts: 241
Default

Once you have the position of the starting and ending ##'s (pos1 and pos2) you could use something like:
Code:
extractedstring = Mid(str1, pos1 + 2, pos2 - pos1 - 2)
To extract the information between the first ## and the second ##.
Also, you might need to change:
Code:
pos2 = Instr(pos1,str1,"##") 'to pos2 = InStr(pos1 + 1, str1, "##")
Reply With Quote
  #5  
Old 08-19-2003, 01:20 AM
ashish908 ashish908 is offline
Contributor
 
Join Date: Feb 2002
Location: Mumbai, India
Posts: 470
Default

Thanks J0n in looking at the fine details
__________________
Success comes from knowing that you did your best to become the best that you are capable of becoming.
--John Wooden
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a file in dat question ? murphys General 5 11-06-2002 08:34 PM
Open an associated Text Document knoxitis General 19 05-01-2002 11:26 PM
Shareware Registry Protection Technigue karachi999 General 2 01-21-2002 02:40 PM
Loop to format file kingesk General 2 09-10-2000 05:01 PM
File format problem kingesk General 1 09-08-2000 04:52 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->