0

我需要做的是這樣的文本文件資源名稱和文件內容:如何獲取所有

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 

我已經試過這種方法,但不爲我工作! :How to get the names of all resources in a resource file

回答

3

這是這樣的:

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 
1

你可以,而你的文件存儲的文件夾中,並通過

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

只是一種替代解決方案訪問它們爲你的問題

+0

謝謝評論 – ElektroStudios