Question

I need to do something like this:

   Private Sub SearchInResources(ByVal PatternSTR As String)
       For Each ResourceFile In My.Resources ' Obviously this don't works
           If ResourceFile.EndsWith(".txt") Then
               Dim fileContent As String = ResourceFile
               Dim stringStream As New System.IO.StringReader(fileContent)
               If stringStream.contains(PatternSTR) Then
                   ' Things...
               End If
           End If
       Next
   End Sub

I've tried this methods but don't work for me! : How to get the names of all resources in a resource file

Était-ce utile?

La solution

This is the way:

    For Each ResourceFile As DictionaryEntry In My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True).OfType(Of Object)()
        If TypeOf (ResourceFile.Value) Is String Then
            MsgBox(My.Resources.ResourceManager.GetObject(ResourceFile.Key))
            'MsgBox(ResourceFile.Key)   ' Resource Name
            'MsgBox(ResourceFile.Value) ' Resource FileContent
        End If
    Next

Autres conseils

You could rather store your files in a folder and access them through

For Each Content As String In My.Computer.FileSystem.GetFiles("D:\Resources", FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
    ListBox1.Items.Add(Content)
Next

just an alternative solution for your problem

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top