如何将变量从数组转换为字符串帮助...使用.GetFiles(searchPattern:="*.jpg") [英] How to get a variable from an array to a string Help... using .GetFiles(searchPattern:="*.jpg")

查看:93
本文介绍了如何将变量从数组转换为字符串帮助...使用.GetFiles(searchPattern:="*.jpg")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好……我已经有几天这个问题了,我似乎没办法解决..

Hi Guys... Ive had this problem for a couple days and i cant seem to figure it out..

这是给我带来麻烦的代码示例.

Here is a sample of the code that is giving me trouble.

私人子listbox1photocheck()
      将Dim photocheck作为DirectoryInfo =新DirectoryInfo(filepath)

      昏暗清单(0)作为数组
       list(0)= photocheck.GetFiles(searchPattern:=" *.jpg")
      昏暗物品As Array = list.ElementAt(0)

      昏暗fullpathway作为字符串= item(全名)

   结束

Private Sub listbox1photocheck()
        Dim photocheck As DirectoryInfo = New DirectoryInfo(filepath)

        Dim list(0) As Array
        list(0) = photocheck.GetFiles(searchPattern:="*.jpg")
        Dim item As Array = list.ElementAt(0)

        Dim fullpathway As String = item(fullname)

    End Sub

基本上,我想要此代码执行的操作是获取目录"filepath",该目录在另一个子目录中选择,并且每个jpg文件都应添加到Array(list)中.我能够做到这一点.但是现在我希望它在上面显示所有这些照片 屏幕上,我认为最好的方法是将jpg图像的文件路径转换为字符串.有人可以帮我吗?谢谢..

Basically what i want this code to do is take the directory of "filepath", which is picked in another sub, and every jpg file should be added into an Array(list). I was able to get that done. But now i want it to display all of those photos on screen and i thought the best way to do that would be to take the filepath of the jpg image and turn it into a string. Could anyone help me ? Thank you..

推荐答案

这就是我要做的.我插入了评论来解释我在做什么.  我的示例代码需要一个名为"lstImages"的列表框,在您的表格上.  您可以轻松地将其更改为输出到文本框或类似的内容(如果您不需要的话) 列表框.

Here is what I would do.  I've inserted comments to explain what I'm doing.  My example code expects a listbox called "lstImages" to be on your form.  You could easily change this to output to a textbox or something similar if you don't want a listbox.

Private Sub listbox1photocheck()
        Dim photocheck As DirectoryInfo = New DirectoryInfo(filepath)

        Dim fileList() As String 'Creates an array of strings

        fileList = photocheck.GetFiles("*.jpg") 'We don't need to included the "searchPattern:=" part if we don't want to.

        'Now we need to loop through our array to put the items in the listbox
        For Each file as string in fileList
             lstImages.items.add(file)
        Next
    End Sub

除了循环,您还可以将数组绑定到列表,但是我认为,循环现在将变得更容易理解.

Instead of the loop, you could also bind the array to the list, but I think a loop is going to be easier to understand for now.

希望有帮助.  如果您对代码的功能有疑问,请询问!  最终,我想确保您了解代码以及代码的工作方式.

Hope that helps.  If you have questions about what the code is doing, please ask!  Ultimately I want to make sure you understand the code and how it's doing what it does.

祝你好运


这篇关于如何将变量从数组转换为字符串帮助...使用.GetFiles(searchPattern:="*.jpg")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆