locked
.Net Strip String to Left RRS feed

  • Question

  • User1210767569 posted

    I have the below code working in it's own project but line For Each separator In {"-", "_", " "} fails in my VB.net project. Is this part c#? I have tried converting with no joy. http://www.developerfusion.com/tools/convert/csharp-to-vb/?batchId=c98c4294-68a0-4d85-a5ee-e01a95fcd5dc 

    Dim fileName = "1_2.pdf".Trim() ' Trim used to show you the method, here nonsense
    Dim name = Path.GetFileNameWithoutExtension(fileName).Trim()
    For Each separator In {"-", "_", " "}
        Dim index = name.IndexOf(separator)
        If index >= 0 Then
            name = name.Substring(0, index)
        End If
    Next
    fileName = String.Format("{0}{1}", name, Path.GetExtension(fileName))

    Friday, June 13, 2014 9:34 AM

Answers

  • User-821857111 posted
    For Each separator In New Char(){"-", "_", " "}



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 13, 2014 9:40 AM

All replies