Help with Regular Expression for save file.txt

Hi to all,
not being good with regular expressions, I would need some help.
I have to collect some documents and save them with the name and tag with which they are collected.
To do this, I have to remove the special characters that can generate errors from the filename.
Specifically, I have to save the files as .txt, but I think the extension doesn’t make a difference.

  • " OB Mobile: create schema (do not run)1 Create cases table.txt "

in the example above, the file name contains both : and (
which I believe generate an error in saving the file.

Can anyone help me to find the string to remove all characters not possible when saving a file?
thanks a lot… :expressionless:
Aaron

Hi,

Can you try the following expression?

yourFileName = System.Text.RegularExpressions.Regex.Replace(yourFileName,"["+System.Text.RegularExpressions.Regex.Escape(String.Join("",System.IO.Path.GetInvalidFileNameChars()))+"]","")

Regards,

2 Likes

Hi @AaronMark

System.Text.RegularExpressions.Regex.Replace(“OB Mobile: create schema (do not run)1 Create cases table”,"[^ .A-Za-z0-9]+","")

Regards
Gokul

1 Like

Top Gokul001

It Work !! Thanks a lot…

With these steps, I solved my problem.

image

image

Thanks again.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.