r/visualbasic • u/mudderfudden • Jun 05 '21
VB.NET Help How would I create a Find and Replace system?
I would like to create a sort of hardcoded "Find & Replace" system. Currently in an app I have, all items loaded in a list (items are folder names) will display in a ComboBox. A couple of the names are not accurate, because they contain illegal characters, or characters not allowed as folder names. Therefore, I would like create either a two-dimensional list or array, I'm not sure which. The first column would basically be "Find what" and the second column would be "replace with". What's the best way to create a system that will do this?
See the table for sample data.
| Find What | Replace With |
|---|---|
| First-Name | First/Name |
| Second- Name | Second: Name |
As you can see, any time there is an illegal character, it replaces it with a dash, thus just searching for the dash and replacing it with the same character each time would not work.
I can probably figure out how to implement it, myself, once I know the best way to define it.
1
u/RJPisscat Jun 05 '21
Is this the same music app you've been working on? If so, have you changed the hierarchy of the file system to folders with Artist Name/Album Name/ and under that a set of pictures with standard names like "front-cover.jpg" and "back-cover.jpg" and so forth? And if so, is this question about how to display the names of bands and albums in a human-legible format instead of the format forced on you by limitations of the file-naming system?
If so, are you cataloging the bands/albums in a database, or using the file system as the catalog? If the latter, you can put an Info.Txt (or better yet, Info.Xml or Info.Json) file inside each of those directories. If the file exists in a subdirectory, it has information about display name of the artist or album, and by using an Info file in one of those formats (json is the most portable of those three), you can later add items you may want to store in addition, such as the names of the band members, or the playing time of an album. If you take this approach it's something you'd want to do on the fly as each folder is created, and now at this stage of development you want to go back and fix the names you've already created while testing this app, and the question makes sense for doing that.
Am I correct? If not, set me straight, and if so, let's work from there.