I have a variable with a path to a file I want to save and want to strip out any invalid characters that would cause the save or later move to fail. It worked fine for a batch but now failing again. I was going to remove the characters but for now just put a space in there. So here's an example:
- foreach (char c in System.IO.Path.GetInvalidFileNameChars())
- {
- item.Snippet.Title = item.Snippet.Title.Remove(c, ' ');
- }
Unhandled Exception: System.ArgumentOutOfRangeException: Index and count must refer to a location within the string.
Parameter name: count
at System.String.Remove(Int32 startIndex, Int32 count)
at ShowWebsiteDownloader.Program.Main() in C:\Users\syarbrou.ICEO\source\repos\ShowWebsiteDownloader\ShowWebsiteDownloader\Program.cs:line 278
At the start of that loop item.Snippet.Title contains:
Disney Fort Wilderness Halloween Staycation Check In Day! | Cabin Tour, Holiday Decorations & BBQ!
Thoughts what's going on?

Sachin SinghRank #66 · 26.2K reputationPosted Nov 7, 2020, 4:04 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Nov 7, 2020, 4:41 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Nov 7, 2020, 4:54 AM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 7, 2020, 9:18 PM EST