- What characters are illegal path?
- How do you fix illegal characters in path?
- What are invalid fileName characters?
- How do you remove an illegal character from a string?
What characters are illegal path?
Solution 1
The "Illegal characters" exception means that the file path string you are passing to ReadXml is wrong: it is not a valid path. It may contain '?' , or ':' in the wrong place, or '*' for example. You need to look at the value, check what it is, and work out where the illegal character(s) are coming from.
How do you fix illegal characters in path?
You can simply use C# inbuilt function " Path. GetInvalidFileNameChars() " to check if there is invalid character in file name and remove it. var InvalidCharacters= Path. GetInvalidFileNameChars(); string GetInvalidCharactersRemovedString= new string(fileName .
What are invalid fileName characters?
Don't start or end your filename with a space, period, hyphen, or underline. Keep your filenames to a reasonable length and be sure they are under 31 characters. Most operating systems are case sensitive; always use lowercase. Avoid using spaces and underscores; use a hyphen instead.
How do you remove an illegal character from a string?
Example of removing special characters using replaceAll() method
- public class RemoveSpecialCharacterExample1.
- public static void main(String args[])
- String str= "This#string%contains^special*characters&.";
- str = str.replaceAll("[^a-zA-Z0-9]", " ");
- System.out.println(str);