Hi guys

I need to find next highest no in a field that is a stick ref it has chars at front and 0 padded

How so I strip off front chars and 0's to get actual highest no number in the table field?

Am using LINQ against entity framework

cheers

George

Recommended Answers

Do you have an example of the data or even the code you're tried?

Jump to Post

All 4 Replies

Do you have an example of the data or even the code you're tried?

Sample of the data would be company number (5660303) plus no so

566030300001
566030300002
566030300003
566030300004

Not tried code as I was a bit stuck with LINQ not used it apart from basic queries

Technique 1:

Imports System.Collections.Generic
Imports System.Linq

Module Module1
   Sub Main()
      Dim lst_strNums As New List(Of String) From _
         {"566030300001", "566030300002", "566030300003", "566030300004"}

      Dim strMax As String = lst_strNums.Select(Function(s) s.Substring(7, 5)).Max()

      Console.WriteLine(strMax)
   End Sub

End Module

Technique1 + Technique2:

Imports System.Collections.Generic
Imports System.Linq

Module Module1
   Function Max1(ByVal lst_str As List(Of String)) As String
      Return lst_str.Select(Function(s) s.Substring(7, 5)).Max()
   End Function
   Function Max2(ByVal lst_str As List(Of String)) As String
      Return lst_str.Select(Function(s) s).Max()
   End Function

   Sub Main()
      Dim lst_strNums As New List(Of String) From _
         {"566030300001", "566030300002", "566030300003", "566030300004"}

      Console.WriteLine(Integer.Parse(Max1(lst_strNums)))
      Console.WriteLine(Integer.Parse(Max2(lst_strNums).Substring(7, 5)))
   End Sub

End Module
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.