本文介绍了如何提取子串的多次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


使用VS.NET 2003 VB。如果我有一个类似于附件的字符串,那么我将如何提取Truckname =循环中的数据并保持循环直到

到达字符串的结尾?如你所见,第一个卡车名是

" 284165"。下一个货车名称是284193


任何帮助都将非常感谢。


谢谢,

Tony


< TruckConduitDataObject>< Truck XVIN =" 67112637" TruckName =" 284165"

OrganizationID =" 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive =" true"

Odo =" 1874679.8" OdoAsOf =" 2006-04-19T20:43:00.0000000-05:00"

FormattedDateTime =" 04/19/06 04:43p"车轴= QUOT; 2英寸Berth =" false"

HasOnBoardPlatform =" true" HasDIU = QUOT;真" />< Truck XVIN =" 67112638"

TruckName =" 284193" OrganizationID = QUOT; 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive =" true"

Odo =" 1633058.2" OdoAsOf =" 2006-04-19T20:21:00.0000000-05:00"

FormattedDateTime =" 04/19/06 04:21p"车轴= QUOT; 3英寸Berth =" false"

HasOnBoardPlatform =" true" HasDIU = QUOT;真" />< Truck XVIN =" 67112639"

TruckName =" 294934" OrganizationID = QUOT; 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive =" true"

Odo =" 128325.5" OdoAsOf =" 2006-04-19T14:43:00.0000000-05:00"

FormattedDateTime =" 04/19/06 10:43a"车轴= QUOT; 3英寸Berth =" false"

HasOnBoardPlatform =" true" HasDIU = QUOT;真" />< Truck XVIN =" 67112640"

TruckName =" 241486" OrganizationID = QUOT; 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive =" true"

Odo =" 249414.5" OdoAsOf =" 2006-04-19T04:00:00.0000000-05:00"

FormattedDateTime =" 04/19/06 12:00a"车轴= QUOT; 3英寸Berth =" false"

HasOnBoardPlatform =" true" HasDIU = QUOT;真" />< Truck XVIN =" 67112641"

TruckName =" 447859" OrganizationID = QUOT; 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive = QUOT;真" Odo =" 283377"

OdoAsOf =" 2006-04-19T20:44:00.0000000-05:00" FormattedDateTime =" 04/19/06

04:44p"车轴= QUOT; 3英寸泊位= QUOT假QUOT; HasOnBoardPlatform = QUOT;真" HasDIU =" true"

OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive = QUOT;真" Odo =" 86711.9"

OdoAsOf =" 2006-04-19T20:40:00.0000000-05:00" FormattedDateTime =" 04/19/06

04:40p"车轴= QUOT; 3英寸泊位= QUOT假QUOT; HasOnBoardPlatform = QUOT;真" HasDIU =" true"

OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive =" true"

Odo =" 185236.2" OdoAsOf =" 2006-04-19T04:00:00.0000000-05:00"

FormattedDateTime =" 04/19/06 12:00a"车轴= QUOT; 3英寸Berth =" false"

HasOnBoardPlatform =" true" HasDIU = QUOT;真" />< Truck XVIN =" 67112667"

TruckName =" 251638" OrganizationID = QUOT; 1214" OrganizationName =" Croydon Dry"
DateOfQuery =" 2006-04-19T21:56:08.3700000-05:00" IsActive = QUOT;真" Odo =" 0"

OdoAsOf =" 1990-01-01T00:00:00.0000000-06:00" FormattedDateTime =" 12/31/89

07:00p"车轴= QUOT; 3英寸泊位= QUOT假QUOT; HasOnBoardPlatform = QUOT假QUOT; HasDIU =" false"

/>< / TruckConduitDataObject>

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

<TruckConduitDataObject><Truck XVIN="67112637" TruckName="284165"
OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true"
Odo="1874679.8" OdoAsOf="2006-04-19T20:43:00.0000000-05:00"
FormattedDateTime="04/19/06 04:43p" Axles="2" Berth="false"
HasOnBoardPlatform="true" HasDIU="true" /><Truck XVIN="67112638"
TruckName="284193" OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true"
Odo="1633058.2" OdoAsOf="2006-04-19T20:21:00.0000000-05:00"
FormattedDateTime="04/19/06 04:21p" Axles="3" Berth="false"
HasOnBoardPlatform="true" HasDIU="true" /><Truck XVIN="67112639"
TruckName="294934" OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true"
Odo="128325.5" OdoAsOf="2006-04-19T14:43:00.0000000-05:00"
FormattedDateTime="04/19/06 10:43a" Axles="3" Berth="false"
HasOnBoardPlatform="true" HasDIU="true" /><Truck XVIN="67112640"
TruckName="241486" OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true"
Odo="249414.5" OdoAsOf="2006-04-19T04:00:00.0000000-05:00"
FormattedDateTime="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatform="true" HasDIU="true" /><Truck XVIN="67112641"
TruckName="447859" OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true" Odo="283377"
OdoAsOf="2006-04-19T20:44:00.0000000-05:00" FormattedDateTime="04/19/06
04:44p" Axles="3" Berth="false" HasOnBoardPlatform="true" HasDIU="true"
/><Truck XVIN="67112642" TruckName="425218" OrganizationID="1214"
OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true" Odo="86711.9"
OdoAsOf="2006-04-19T20:40:00.0000000-05:00" FormattedDateTime="04/19/06
04:40p" Axles="3" Berth="false" HasOnBoardPlatform="true" HasDIU="true"
/><Truck XVIN="67112662" TruckName="211103" OrganizationID="1214"
OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true"
Odo="185236.2" OdoAsOf="2006-04-19T04:00:00.0000000-05:00"
FormattedDateTime="04/19/06 12:00a" Axles="3" Berth="false"
HasOnBoardPlatform="true" HasDIU="true" /><Truck XVIN="67112667"
TruckName="251638" OrganizationID="1214" OrganizationName="Croydon Dry"
DateOfQuery="2006-04-19T21:56:08.3700000-05:00" IsActive="true" Odo="0"
OdoAsOf="1990-01-01T00:00:00.0000000-06:00" FormattedDateTime="12/31/89
07:00p" Axles="3" Berth="false" HasOnBoardPlatform="false" HasDIU="false"
/></TruckConduitDataObject>

推荐答案




这一切都在一行吗?



Is this all in one line?





Tony,我做了几个假设以下代码 -


1.您正在读取文件中的数据

2. TruckName数据总是6个字符


我希望你能够将这里写的内容应用到你特定的

要求。


Dim sFileName As String = " C:\Temp \TruckData.txt"

Dim sA As String = File.ReadAllText(sFileName)

Dim X As Integer = 0


Do

X = sA.IndexOf(" TruckName =",X)

如果X<> -1然后

X + = 11

Debug.Print(sA.Substring(X,6))

Else

退出运行

结束如果

循环


我根据您提供的数据对其进行了测试,它运行良好。 />

相信这会有所帮助。


ShaneO


有10种人 - 了解二元的人那些

不要。



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\TruckData.txt"
Dim sA As String = File.ReadAllText(sFileName)
Dim X As Integer = 0

Do
X = sA.IndexOf("TruckName=", 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.




哎呀!忘了告诉你添加NameSpace -


Imports System.IO


ShaneO


有10种人 - 那些了解Binary和那些

的人不会。


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.


这篇关于如何提取子串的多次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:40