API 2.0: String.CountFieldsB Conversion

Hi,

couldn’t find out, how to translate this into API 2.0. Any suggestions?

Dim fileName As String = "test.txt"
Dim n As Integer = CountFieldsB(fileName, ".")

if n > 1 then
  Return fileName.NthField(".", n)
else
  return ""
end

Thanks

Why do you want to use CountFieldsB at all? The filename is utf8.

I just fully convert an old Project from another one to API 2.0. Xojo tells me, CountFieldsB ist deprecated, use MemoryBlock instead. This is the only point still open. The file name is only an example. :wink:

What @Beatrix_Willius means is, why do you count the Bytes at all? Just remove the B in CountFieldsB and be good. :slight_smile:
Maybe, just make sure you’re always dealing with UTF8.

Dim n As Integer = fileName.CountFields(“.”)

Another option is to use Split, perhaps with something like this:

Dim fileName As String = "test.txt"

Var parts() As String = fileName.Split(".")
If parts.LastRowIndex > 0 Then
  Return parts(parts.LastRowIndex)
Else
  Return ""
End If
1 Like