简体   繁体   English

在 VB.Net 中过滤字符串

[英]Filtering a string in VB.Net

I am awful and VB.Net, so I am kind of lost what to do with this string to filter.我很糟糕而且 VB.Net,所以我有点迷失如何处理这个字符串来过滤。

I have a string: "294.00" & vbCrLf & "$10,831.99" & vbCrLf & "191 lbs." & vbCrLf & "15,929 lbs."我有一个字符串: "294.00" & vbCrLf & "$10,831.99" & vbCrLf & "191 lbs." & vbCrLf & "15,929 lbs." "294.00" & vbCrLf & "$10,831.99" & vbCrLf & "191 lbs." & vbCrLf & "15,929 lbs."

And basically, I need to grab the second numeric value: 10,831.99 and filter the rest of the junk out.基本上,我需要获取第二个数值: 10,831.99并将垃圾的 rest 过滤掉。

I am not sure how to go about this.我不知道如何 go 关于这个。 Possibly REGEX( which I have no idea how to use in VB.NET) or maybe some other build in functionality from the standard LIB?可能是 REGEX(我不知道如何在 VB.NET 中使用它)或标准 LIB 中的其他一些内置功能?

I have tried: myString.Split(Environment.NewLine)(0).ToString()我试过: myString.Split(Environment.NewLine)(0).ToString()

But I only get the first numeric value: 294.00 which is the incorrect one.但我只得到第一个数值: 294.00 ,这是不正确的。

any input or advice/tips would be appreciated!任何输入或建议/提示将不胜感激! Thanks谢谢

you already solved your problem, let me explain.你已经解决了你的问题,让我解释一下。

this function myString.Split returns an array, you can access each element of the array using the index [ the (0) means you are accessing the string at the 0 position ].这个 function myString.Split返回一个数组,您可以使用索引访问数组的每个元素 [ (0)表示您正在访问 0 position 处的字符串]。 So, if you want the second value you can do it just like this:所以,如果你想要第二个值,你可以这样做:

myString.Split(Environment.NewLine)(1).ToString()

for more information about string split visit the link below: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.split?view=net-5.0有关字符串拆分的更多信息,请访问以下链接: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.split?view=net-5.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM