954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

LINQ query stripping of front chars then Highest no

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

Ggalla1779
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

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

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

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

Ggalla1779
Newbie Poster
5 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

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
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

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
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: