Чтобы использовать метод расширения IEnumerable.Last(Of TSource)
, ваш проект должен быть нацелен на .NET 3.5 или выше.
Пожалуйста, смотрите пример кода ниже:
Option Strict On
Option Explicit On
' The imports below are only required if the namespace(s)
' have not been imported into your project's settings
Imports System.Linq ' Requires .NET 3.5 or higher
Imports Microsoft.VisualBasic ' This is required to use the Visual Basic functions like Mid(), InStr(), MsgBox(), etc...
Module Module1
Sub Main()
Dim str As String = "This is a string of words"
Dim delim As Char = " "c
Dim strArr As String() = str.Split(delim)
Dim lastWord As String
' Requires the Microsoft Visual Basic namespace to be imported
lastWord = Mid(str, InStrRev(str, delim) + 1I)
lastWord = Mid(str, str.LastIndexOf(delim) + 2I)
' These are safe for .NET 2.0 and higher:
lastWord = strArr(strArr.Length - 1I)
lastWord = strArr(strArr.GetUpperBound(0I))
' These require .NET 3.5 and higher:
lastWord = (From word As String In strArr Select word).Last
lastWord = strArr.Last
lastWord = strArr.ElementAt(strArr.GetUpperBound(0I))
End Sub
End Module
ли мы считать 'currentPriceString' это та же строка, как' str'? Всегда отправляйте реальный код. – LarsTech