2

I have code in C#

string fileNameOnly = Path.GetFileNameWithoutExtension(sKey);
string token = fileNameOnly.Remove(fileNameOnly.LastIndexOf('_'));
string number = new string(token.SkipWhile(Char.IsLetter).ToArray());

And i want it in VB

Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sKey)
Dim token As String = fileNameOnly.Remove(fileNameOnly.LastIndexOf("_"c))
Dim number As New String(token.SkipWhile([Char].IsLetter).ToArray())

I have tried that but did not work! Is there something similar to use. What it does is look at a file name and only use the number part of it and skip all letters and all after _.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
user3458266
  • 235
  • 1
  • 5
  • 12

1 Answers1

1

You have to use AddressOf in VB.NET:

Dim number As New String(token.SkipWhile(AddressOf Char.IsLetter).ToArray())

You could also use Function:

Dim number As New String(token.SkipWhile(Function(c)Char.IsLetter(c)).ToArray())

In VB.NET i often use multiple lines and combine query+method syntax to avoid the ugly Function/AddressOf keywords.

Dim numberChars = From c In token
                  Skip While Char.IsLetter(c)
Dim numbers = New String(numberChars.ToArray())
Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939