Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,988 questions

51,933 answers

573 users

How to extract the last number from a string in VB.NET

3 Answers

0 votes
Imports System
Imports System.Linq

Public Class Program
	Public Shared Sub Main()
        Dim str As String = "98 vb programming 15"
		
        Dim number As Integer = Integer.Parse(str.Split().Last())
		
        Console.Write(number)
    End Sub
End Class



' run:
'
' 15
'

 



answered Aug 30, 2023 by avibootz
0 votes
Imports System
Imports System.Text.RegularExpressions

Public Class Program
	Public Shared Sub Main()
        Dim str As String = "98 vb programming15"
		
        Dim arr As String() = Regex.Split(str, "\D+")
		
        Dim number As Integer = Integer.Parse(arr(arr.Length - 1))
		
        Console.Write(number)
    End Sub
End Class




' run:
'
' 15
'

 



answered Aug 30, 2023 by avibootz
0 votes
Imports System
Imports System.Text.RegularExpressions

Public Class Program
    Public Shared Function get_last_number(ByVal str As String) As Integer
        Dim arr As String() = Regex.Split(str, "\D+")
        
		Return Integer.Parse(arr(arr.Length - 1))
    End Function

    Public Shared Sub Main()
        Dim str As String = "98 vb 22 programming15"
		
        Dim number As Integer = get_last_number(str)
		
        Console.Write(number)
    End Sub
End Class





' run:
'
' 15
'

 



answered Aug 30, 2023 by avibootz

Related questions

1 answer 132 views
1 answer 156 views
1 answer 123 views
2 answers 111 views
1 answer 143 views
2 answers 115 views
...