473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Find what comes after a match in a string

Hi.

I'm trying to find out (isolate) the numbers that following a certain text match in a string.

Example: "pageid=4&ctl=allowed&sectionid=235&numberid=5 5"

In this example, I want to find the text match of "sectionid=". I then want whatever numbers are are after it - in this case it would be "235". But I need ONLY the numbers that fall between "sectionid=" and "&numberid=", since the numbers could be any amount (eg. 235, 2000000, 2, etc).

Thank you for your time and assistance!!!
Apr 10 '15 #1

✓ answered by IronRazer

You can do this using a few of the String methods or by using RegularExpressions. It would be best to learn the String methods before jumping into RegularExpressions though. That can be a little confusing if you are not used to it.

Here is a simple example you can check out.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim str As String = "pageid=4&ctl=allowed&sectionid=235&numberid=5 5"
  3.  
  4.         Dim find As String = "sectionid="
  5.         Dim startindex As Integer = str.IndexOf(find)
  6.         Dim endindex As Integer = str.IndexOf("&", startindex)
  7.  
  8.         Dim number As String = str.Substring(startindex + find.Length, endindex - (startindex + find.Length))
  9.  
  10.         MessageBox.Show(number)
  11.     End Sub
  12.  

2 1488
IronRazer
83 64KB
You can do this using a few of the String methods or by using RegularExpressions. It would be best to learn the String methods before jumping into RegularExpressions though. That can be a little confusing if you are not used to it.

Here is a simple example you can check out.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim str As String = "pageid=4&ctl=allowed&sectionid=235&numberid=5 5"
  3.  
  4.         Dim find As String = "sectionid="
  5.         Dim startindex As Integer = str.IndexOf(find)
  6.         Dim endindex As Integer = str.IndexOf("&", startindex)
  7.  
  8.         Dim number As String = str.Substring(startindex + find.Length, endindex - (startindex + find.Length))
  9.  
  10.         MessageBox.Show(number)
  11.     End Sub
  12.  
Apr 12 '15 #2
Ahhh ... perfect! Thank you!

I was trying to do this with a method of ".Split("sectionid=") to parse out the info. Mistake.

Your solution is exactly where I should have been going from the start.
Apr 13 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Christopher Parent | last post by:
I have perused through the groups and a couple C++ manuals and haven't been able to figure this one out. Maybe I'm staring at it too much. Here's the setup, I have 2 files. One is a library and one...
3
by: skosmicki | last post by:
I need to create an function similar to the "MATCH" function in Excel that evaluates a number within a set of numbers and returns whether there is a match. I have put the example of what I see in...
1
by: justin.mayes | last post by:
hello all - An example. You have a regular expression to locate certain html tags. "(<)" This will find every instance of a "<" character that is not followed by a letter. The match will...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
3
by: Edwin Smith | last post by:
Hello: I have the following code which works on a DataGridView binding source: private void textBox1_TextChanged(object sender, EventArgs e) { this.pATIENTSBindingSource.Position =...
11
by: Flyzone | last post by:
Hello, i have again problem with regexp :-P I need to match all lines that contain one word but not contain another. Like to do "grep one | grep -v two:" The syntax of the string is: (any...
2
by: RiverstoneJebin | last post by:
Hi, I have 2 tables with same fields like event, venue, date and cost. Table 1 has 5 records and Table 2 has 100 records. How can i match a record from Table 1 with Table 2 to get the exact match...
2
by: Sejoro | last post by:
Hello, I am trying to write a program that opens a file; reads through it; outputs the text; then outputs the number of lines, words, and characters. Problem is, every time I try to compile, no...
2
by: Fernando | last post by:
Hi, How can I find if the current document contains a certain substring? Thanks!
1
by: imhotep | last post by:
bool isQstr(string const& str) { size_t found = str.find("\""); return found != string::npos; } /* I am trying to check whether a string contains a quoted string, I used the escape...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.