473,671 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extract multiple occurrences of a substring

Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how would
i extract the "Truckname= " data from it in a loop and stay in the loop until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"

Any help would be gratefully appreciated.

Thanks,
Tony

<TruckConduitDa taObject><Truck XVIN="67112637" TruckName="2841 65"
OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1874679.8" OdoAsOf="2006-04-19T20:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:43p" Axles="2" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112638"
TruckName="2841 93" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1633058.2" OdoAsOf="2006-04-19T20:21:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:21p" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112639"
TruckName="2949 34" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="128325.5" OdoAsOf="2006-04-19T14:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 10:43a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112640"
TruckName="2414 86" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="249414.5" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112641"
TruckName="4478 59" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true" Odo="283377"
OdoAsOf="2006-04-19T20:44:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:44p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112642" TruckName="4252 18" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true" Odo="86711.9"
OdoAsOf="2006-04-19T20:40:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:40p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112662" TruckName="2111 03" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="185236.2" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112667"
TruckName="2516 38" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true" Odo="0"
OdoAsOf="1990-01-01T00:00:00.000 0000-06:00" FormattedDateTi me="12/31/89
07:00p" Axles="3" Berth="false" HasOnBoardPlatf orm="false" HasDIU="false"
/></TruckConduitDat aObject>
Apr 19 '06 #1
13 2710

"Tony Girgenti" <To**********@d iscussions.micr osoft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how
would
i extract the "Truckname= " data from it in a loop and stay in the loop
until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"


Is this all in one line?

Apr 19 '06 #2
Tony Girgenti wrote:
Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how would
i extract the "Truckname= " data from it in a loop and stay in the loop until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"

Any help would be gratefully appreciated.


Tony, I have made a couple of assumptions with the following code -

1. You are reading data from a file
2. The TruckName data is always 6 chars long

I hope you'll be able to apply what's written here to your specific
requirements.

Dim sFileName As String = "C:\Temp\TruckD ata.txt"
Dim sA As String = File.ReadAllTex t(sFileName)
Dim X As Integer = 0

Do
X = sA.IndexOf("Tru ckName=", X)
If X <> -1 Then
X += 11
Debug.Print(sA. Substring(X, 6))
Else
Exit Do
End If
Loop

I tested it on your supplied data and it works perfectly.

Trust this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Apr 19 '06 #3
ShaneO wrote:

Dim sFileName As String = "C:\Temp\TruckD ata.txt"
Dim sA As String = File.ReadAllTex t(sFileName)
Dim X As Integer = 0

Do
X = sA.IndexOf("Tru ckName=", X)
If X <> -1 Then
X += 11
Debug.Print(sA. Substring(X, 6))
Else
Exit Do
End If
Loop

Oops! Forgot to tell you to add the NameSpace -

Imports System.IO

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Apr 20 '06 #4
Shane.

Thanks alot. That worked beautifully.
Excellent.

Thanks again,
Tony
"ShaneO" wrote:
Tony Girgenti wrote:
Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how would
i extract the "Truckname= " data from it in a loop and stay in the loop until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"

Any help would be gratefully appreciated.


Tony, I have made a couple of assumptions with the following code -

1. You are reading data from a file
2. The TruckName data is always 6 chars long

I hope you'll be able to apply what's written here to your specific
requirements.

Dim sFileName As String = "C:\Temp\TruckD ata.txt"
Dim sA As String = File.ReadAllTex t(sFileName)
Dim X As Integer = 0

Do
X = sA.IndexOf("Tru ckName=", X)
If X <> -1 Then
X += 11
Debug.Print(sA. Substring(X, 6))
Else
Exit Do
End If
Loop

I tested it on your supplied data and it works perfectly.

Trust this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Apr 20 '06 #5
And everyone forgets the power of RegEx!!!

This is off the top of my head:

Dim strHtml As String = "Your string here........... ........."

' Capture the TruckName.
Dim regTruckName As New RegularExpressi ons.Regex( _
"TruckName\=\"" (\d{6})\""", _
Options:=Regula rExpressions.Re gexOptions.Sing leline)

Dim m As RegularExpressi ons.Match

For Each m In regTruckName.Ma tches(strHtml)
'Trace.WriteLin e(strNewLine)
Dim mLink As RegularExpressi ons.Match

And gives the output of all truck names!
--
|
+-- JDMils
|
"Tony Girgenti" <To**********@d iscussions.micr osoft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how
would
i extract the "Truckname= " data from it in a loop and stay in the loop
until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"

Any help would be gratefully appreciated.

Thanks,
Tony

<TruckConduitDa taObject><Truck XVIN="67112637" TruckName="2841 65"
OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1874679.8" OdoAsOf="2006-04-19T20:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:43p" Axles="2" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112638"
TruckName="2841 93" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1633058.2" OdoAsOf="2006-04-19T20:21:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:21p" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112639"
TruckName="2949 34" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="128325.5" OdoAsOf="2006-04-19T14:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 10:43a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112640"
TruckName="2414 86" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="249414.5" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112641"
TruckName="4478 59" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="283377"
OdoAsOf="2006-04-19T20:44:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:44p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112642" TruckName="4252 18" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="86711.9"
OdoAsOf="2006-04-19T20:40:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:40p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112662" TruckName="2111 03" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="185236.2" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112667"
TruckName="2516 38" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true" Odo="0"
OdoAsOf="1990-01-01T00:00:00.000 0000-06:00" FormattedDateTi me="12/31/89
07:00p" Axles="3" Berth="false" HasOnBoardPlatf orm="false" HasDIU="false"
/></TruckConduitDat aObject>

Apr 20 '06 #6
>> And everyone forgets the power of RegEx!!!

Yeah ! This is a perfect candidate for the application of Regex !

Regards,

Cerebrus.

Apr 20 '06 #7
JDMils wrote:
And everyone forgets the power of RegEx!!!

Hmmm... For simplicity, speed and readability I personally don't believe
the RegEx Class was needed in this case, and besides, who among us has
really had the time (or inclination) to learn all the RegEx
Methods/Properties??

Just my opinion!

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Apr 20 '06 #8
>> For simplicity, speed and readability I personally don't believe
the RegEx Class was needed in this case
I don't know about the performance comparison between using String
methods and using the Regex engine. I haven't been able to find any
comparisons out there, so if you know of any, please let me know.
besides, who among us has really had the time (or inclination) to learn all the RegEx
Methods/Properties


They aren't that many, you know. And when you do learn them, you will
wield a very powerful tool in your hands !

Regards,

Cerebrus.

Apr 20 '06 #9
Looks like XML to me, so how about taking advantage of that

Dim doc As New System.Xml.XmlD ocument
doc.LoadXml(myS tring)
Dim baseNode As System.Xml.XmlN ode =
doc.SelectSingl eNode("TruckCon duitDataObject" )
Dim nodes As System.Xml.XmlN odeList = baseNode.Select Nodes("Truck")

For Each node As System.Xml.XmlN ode In nodes
Dim name As System.Xml.XmlA ttribute = node.Attributes ("TruckName" )
If name IsNot Nothing Then
' Do stuff with the name
End If
Next

/claes

"Tony Girgenti" <To**********@d iscussions.micr osoft.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
Hello.

Using VS.NET 2003 VB. If i have a string similar to the attached, how
would
i extract the "Truckname= " data from it in a loop and stay in the loop
until
the end of the string is reached ? As you can see the first truckname is
"284165". The next truckname is "284193"

Any help would be gratefully appreciated.

Thanks,
Tony

<TruckConduitDa taObject><Truck XVIN="67112637" TruckName="2841 65"
OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1874679.8" OdoAsOf="2006-04-19T20:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:43p" Axles="2" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112638"
TruckName="2841 93" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="1633058.2" OdoAsOf="2006-04-19T20:21:00.000 0000-05:00"
FormattedDateTi me="04/19/06 04:21p" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112639"
TruckName="2949 34" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="128325.5" OdoAsOf="2006-04-19T14:43:00.000 0000-05:00"
FormattedDateTi me="04/19/06 10:43a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112640"
TruckName="2414 86" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="249414.5" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112641"
TruckName="4478 59" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="283377"
OdoAsOf="2006-04-19T20:44:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:44p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112642" TruckName="4252 18" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="86711.9"
OdoAsOf="2006-04-19T20:40:00.000 0000-05:00" FormattedDateTi me="04/19/06
04:40p" Axles="3" Berth="false" HasOnBoardPlatf orm="true" HasDIU="true"
/><Truck XVIN="67112662" TruckName="2111 03" OrganizationID= "1214"
OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true"
Odo="185236.2" OdoAsOf="2006-04-19T04:00:00.000 0000-05:00"
FormattedDateTi me="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatf orm="true" HasDIU="true" /><Truck XVIN="67112667"
TruckName="2516 38" OrganizationID= "1214" OrganizationNam e="Croydon Dry"
DateOfQuery="20 06-04-19T21:56:08.370 0000-05:00" IsActive="true" Odo="0"
OdoAsOf="1990-01-01T00:00:00.000 0000-06:00" FormattedDateTi me="12/31/89
07:00p" Axles="3" Berth="false" HasOnBoardPlatf orm="false" HasDIU="false"
/></TruckConduitDat aObject>

Apr 20 '06 #10

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

Similar topics

1
8628
by: Tim Smith | last post by:
I am looking to extract form element values from html, more generally I have a substring that identifies the beginning of a value and a string that identifies the end of value and I need to extract the substring. My ugly code looks like this: public static String getValue(String data, String begin, String end) { int delimPos = data.indexOf(delim, data.indexOf(begin) +
4
30198
by: rdraider | last post by:
Is there a function that will extract part of a string when the data you want does not occur in a specific position? Field "REF" is varchar(80) and contains an email subject line and the email recipients contact name Example data: Rec_ID REF 1 Here is the information you requested (oc:Johm Smith) 2 Thanks for attending our seminar (oc:Peggy Sue Johnson)
3
2421
by: sparks | last post by:
Besides doing a loop is there a command that will give the number of occurreneces of a chr in a string? The only way I can think of is to do a while loop and count variable. thanks for info Jerry
9
16966
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and extract 35 characters (including "T") from a file and then go to next line?
4
14119
by: sibingpeter | last post by:
Hi there, Im trying to find the right way to code the loop to count the number of occurences of a given substring in a string. Im able to find the first occurence using the strstr function, but I just cant seem to think of the right loop that would continue searching after finding this first occurence. Could someone please help me out here?
3
5050
by: jarod1701 | last post by:
Hi, I'm currently trying to create a regular expression that can extract certain elements from a url. The url will be of the following form: http://user:pass@www.sitename.com I want a regex that matches the "user" part of that url.
1
5690
by: Nick | last post by:
Hi, I'm trying to extract element of a directory path stored in the db with substring "/help/support/index/time.jsp" and i want to extract the 1st, 2nd and 3rd parts 1st = help, 2nd = support, 3rd = index
1
2088
by: Patrick Sullivan | last post by:
I am trying to extract two parts of a number from an array element. Numbers are in the format of 1.10, 2.50, 11.10, etc. Floor and ceiling won't work right because close to 1.00, I get a zero, and I need the actual integer part and the fraction part as an int, too.. TIA here is the data fields(0) = "Alena Sobran" fields(1) = "4/4/1977"
3
1793
by: beary | last post by:
Hi, If I have this: Today is a good day Johnny is good Tomorrow will be better Mary is bad Who cares
0
8402
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
8927
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
8825
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...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7445
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
6237
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
5703
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
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.