How can I check if filename contains a portion of a string in vb.net -
i have userform in 2008 vb express edition. part number created user input via concat string. want check if portion of part number exists in existing file names in directory. below more detailed explanation.
this code creating part number user input on form.
l_partno.text = string.concat(cb_type.text, cb_face.text, "(", t_width.text, "x", t_height.text, ")", mount, t_qty.text, weep, serv)
i have following code tell user if configuration (part no) created exists
l_found.visible = true if file.exists("z:\cut sheets\tcs products\blank out sign\" & (l_partno.text) & ".pdf") l_found.text = "this configuration exists" else l_found.text = "this configuration not exist" end if
this need help. part no bx002(30x30)a1ss want compare 002(30x30) (just part of file name) files in 1 directory. want yes or no answer existance , not list of matching files. code below i've tried, not @ same time.
dim b boolean b = l_partno.text.contains(newface) dim newface string = string.concat(cb_face.text, "(", t_width.text, "x", t_height.text, ")") dim newface = l_partno.text.substring(2, 10) if filename.contains(newface) lnewface.visible = false else lnewface.visible = true end if
the code below translation answer in c# not work either
dim contains boolean = directory.enumeratefiles(path).any(function(f) [string].equals(f, "myfilethree", stringcomparison.ordinalignorecase))
here's example of how can without fancy linq , lambda seem confusing you:
public function filematches(folderpath string, filepattern string, phrase string) boolean each filename string in directory.getfiles(folderpath, filepattern) if filename.contains(phrase) return true end if next return false end function
or, if need case insensitive:
public function filematches(folderpath string, filepattern string, phrase string) boolean each filename string in directory.getfiles(folderpath, filepattern) if filename.tolower().contains(phrase.tolower()) return true end if next return false end function
you call method this:
lnewface.visible = filematches(path, "*.pdf", newface)
Comments
Post a Comment